Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using this code to upload a document to my server.

<?php
if ($_FILES["file"]["error"] > 0){
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}else{
echo getcwd().'<br>';
echo "Upload in file named: " . $_FILES["file"]["name"] . "<br>";
$info = pathinfo($_FILES['userFile']['name']);
$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$target = 'upload/100.'.$ext;
move_uploaded_file( $_FILES['file']['tmp_name'], $target);
}

?>

I am getting these error message:

Warning: move_uploaded_file(C:Inetpubvhostsapi.cutm.ac.inhttpdocsUploadMarksupload100.docx) [function.move-uploaded-file]: failed to open stream: Permission denied in C:Inetpubvhostsapi.cutm.ac.inhttpdocsUploadMarksuploadFile.php on line 14

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:WindowsTempphpF64C.tmp' to 'C:Inetpubvhostsapi.cutm.ac.inhttpdocsUploadMarksupload100.docx' in C:Inetpubvhostsapi.cutm.ac.inhttpdocsUploadMarksuploadFile.php on line 14

What am I doing wrong? What changes do I need in my code? Please help me in this regard.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
300 views
Welcome To Ask or Share your Answers For Others

1 Answer

The problem is that your folder is not having write permission. And because of that it is not uploading the file.

You have to give it write permission. You can also use chmod for giving write permission to that folder.

Also check who is having that write permission for that folder. When you upload the file from code it is uploaded as Other user.

More info


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...