I’m running the following code on a file that has been uploaded to this page through a POST.
$newname = "images/".$name.".".pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION);
//Copy the file from its temporary location to its real location.
if (file_exists("images/".$name))
throw new Exception("images/".$name." already exists.");
move_uploaded_file($_FILES["file"]["tmp_name"], $newname);
echo "Stored in: ".$newname."<BR />";
The file shows up in the correct location on the web server, and it’s the correct size. When I try to view it though it says “… you don’t have the correct permission to access the file location.”
I’m running on Windows 7 testing this on a local Apache web server, and all files for this site are in the same folder (except the uploaded images are held in the /images folder within that folder, but I switched that back and forth and it didn’t help).
What am I doing wrong and how can I stop this permissions problem so I can view the files right after upload?
EDIT
I can access the file if I raise my permissions to administrator and give the file a permissions set for normal users.
I have tried using chmod as suggested in the answer below to change the permissions for all users once the file is uploaded, but that doesn’t seem to work.
This isn’t a tremendous issue because the web server can still use the images which is what I really need – but I’d like to be able to view them without administrator privileges to simplify my test environment a little bit. So any further suggestions are greatly appreciated 🙂
Try running:
To get the octal value of the files chmod settings after it is uploaded e.g.
0755If they are set too low you can use:
To set them to something which will allow you to view them.