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

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.

Member Avatar for LastMitch

@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.

What if I am using a mac? How would I change the permissions then?
Thanks for the help

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.