0

Hello all,
I am working on an upload function and am having problems. This is the message that it says:

Warning: move_uploaded_file(../../../../data/C0017593-Human_brain,_PET_scan-SPL.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/...(other stuff) on line 163

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/Applications/XAMPP/xamppfiles/temp/phpMtgNWy' to '../../../../data/C0017593-Human_brain,_PET_scan-SPL.jpg' in /Applications/XAMPP/xamppfiles/htdocs/...(other stuff) on line 163

Line 163 is "if(move_uploaded_file...etc."
Here is the code:

<?php
        $target_path = "../../../../data/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

//this line of code below is line 163
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?>

I would appreciate any help! I am stuck and have no idea what is wrong! Thanks

3
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by viktor.jiracek.5
0

The server doesn't have permission to write the file to the target directory.

On Linux, you'd need to set the ownership of the directory to the same user as the web server, and the permissions to 755.

Unfortunately I don't use Windows, so I'm not sure exactly how to resolve the problem, but it is permissions based.

0

@viktor.jiracek.5

Warning: move_uploaded_file(../../../../data/C0017593-Human_brain,_PET_scan-SPL.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/...(other stuff) on line 163

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/Applications/XAMPP/xamppfiles/temp/phpMtgNWy' to '../../../../data/C0017593-Human_brain,_PET_scan-SPL.jpg' in /Applications/XAMPP/xamppfiles/htdocs/...(other stuff) on line 163

Line 163 is "if(move_uploaded_file...etc."

What blocblue mention above is right. I was about to explain it more but he explained very clearly.

Another words what blocblue mean that you need to set permissions of the directory so as PHP scripts can run correctly.

You have to set the permissions to read & write for the folder which you are trying to upload to.

Edited by LastMitch: grammer

0

I changed the permission by clicking on the file, going up to Top navigation bar and clicking File. Then, I clicked "Get Info". There is a permissions box there!
Thanks everybody for your help! I definitely appreciate it!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.