Jump to content

Recommended Posts

When I run this,

 

<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    Send this file: <input name="userfile" type="file" /><br />
    <input type="submit" name="submitBtn" value="Send File" />
</form>
<?php
if (isset($_POST['submitBtn'])){




    if (move_uploaded_file($_FILES['userfile']['tmp_name'], "../schedules/")) {
echo "The file: ".  basename( $_FILES['userfile']['name']) . "has been uploaded";

    } else {
        echo "Upload failed!";
    }


}
?> 

 

I go to the schedules directory, and the file is not there even though I get the message:

 

The file: test.doc has been uploaded

Link to comment
https://forums.phpfreaks.com/topic/144811-upload-problem/
Share on other sites

You may wish to add an extra line into your form submission code like this :

 

<INPUT TYPE = "HIDDEN" NAME = "MAX_FILE_SIZE" VALUE = "1300000">

 

put it just before the type="file"  line

 

Also, view your source code to see what is being sent down to the browser in your <FORM> statement, check that it's OK.

 

Check your permissions on your /schedules/ subfolder, you may need to add more "write" permissions

 

Also, I think you need to specify more than just the subfolder in your upload statement, I think you need to specify the whole filename right down to the extension

 

try :

 

$final_file_name = '../schedules/' . basename($_FILES['userfile']['name']);

 

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $final_file_name)) {    //  etc. etc. etc.

 

 

Lemme know if you tried all that and it doesn't work.

Link to comment
https://forums.phpfreaks.com/topic/144811-upload-problem/#findComment-759895
Share on other sites

Yes, you're right - adding the full filename solved it. Thanks.

 

But I wish there was a way to screen an uploaded file for an HTML extension and it it exists, change it to .HTM.  I posted that in an earlier post but there was no solution.

Any ideas?  It "seems" simple enough but my knowledge of php is not quite good enough to pull that off!  :-)

Link to comment
https://forums.phpfreaks.com/topic/144811-upload-problem/#findComment-760638
Share on other sites

$name =  basename($_FILES['userfile']['name']);

if (file_exists('../schedules/' . $name) && stristr($name, ".HTML")) {
    $ext = explode(".", $name);
    $name = str_replace($ext[1], 'HTM', $name);
}

$final_file_name = '../schedules/' . $name;

 

That should take care of that.

 

Link to comment
https://forums.phpfreaks.com/topic/144811-upload-problem/#findComment-760644
Share on other sites

Thanks!  But a question: where does that go.  Is it before or after this section (or replace it):

 

if (move_uploaded_file($_FILES['userfile']['tmp_name'], "../schedules/")) {
   echo "The file: ".  basename( $_FILES['userfile']['name']) . "has been uploaded";

    } else {
        echo "Upload failed!";
    }

Link to comment
https://forums.phpfreaks.com/topic/144811-upload-problem/#findComment-760656
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.