move_uploaded_file php error
Hello I am trying to upload a file a user selects on their local computer to my server through a form but I get the following php error:
Warning: move_uploaded_file(bqformtest/uploaded_files/test.doc) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/drawapl1/public_html/bqformtest/index.php on line 40
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phphhS4QD' to 'bqformtest/uploaded_files/test.doc' in /home/drawapl1/public_html/bqformtest/index.php on line 40
This is my php code:
$target = "bqformtest/uploaded_files/";
$target = $target . basename开发者_开发技巧( $_FILES['upload']['name']) ;
if(move_uploaded_file($_FILES['upload']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
This is my form code:
<form method='post' action='' accept-charset='UTF-8' enctype='multipart/form-data'>
<input type="file" name="upload" size="50" />
<input id="submitButton" type='submit' name='Submit' value='' />
</form>
The uploaded_files folders permissions is set to 755. Thanks in advance.
Provide full path to file, or right relative path
$target = "{fullPath}/fileName";
the path to file is wrong
From what I can tell based on the error message, your script is in ROOT/bqformtest
. Then you are setting $target
to relative path: bqformtest/uploaded_files
. This means the script will try to move the uploaded file from the temp dir to: ROOT/bqformtest
+ bqformtest/uploaded_files
resulting in:ROOT/bqformtest/bqformtest/uploaded_files
. Set $target
to:
$target = "uploaded_files/";
or
$target = "/home/drawapl1/public_html/bqformtest/uploaded_files/";
and it should work.
By the way, you are using the name of the uploaded file without sanitizing it which is a major security risk. Don't trust anything sent by the user.
Also Check disk quota for the user. I had this problem and and after many hours of testing I found it was simple. The user's quota was exceeded
精彩评论