Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

php - Permission denied while uploading a file

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...