Upload Files in PHP (Fedora HTTPD)

I need Upload a Excel File from my user to the server. when the user enters his file that goes to tmp folder, I have to copy same tmp file to my folder.

But it shows me a “Permission” Error!

Why?

/ folder is 777
var folder in / is 777
www in var is 777
html in www is 777
uploadexcel in html is 777
uploads in uploadexcel is 777

but when I copy the same file manually its 711!

Anyone?

1 Like

Sounds like the umask is the issue. Since most sites do not allow anyone except the original poster to edit files the default umask is 022 which prevents files being writeable by anyone other than the owner, and since executeable files are a no-no on any web site then 777 is not the correct permissions. At most they should be 766, and even that is risky since it allow ANYONE to edit the file.

What you should do is have a group that all authorized users are part of and the directory owned by that group. Then the files could be 664 at most and allow the group to edit the files but everyone else could only read them.

I seriously doubt that the files are 711 since that means everyone could execute them even if they could not read them. 744 maybe.

Excuse me I Forgot the numbers
the same file in Uploads folder has
-rwxr–r–

I know Ill just fix this problem…

rwxr–r-- is 744, but files should not even be that in most cases. 644 is rw-r–r-- and that is what you should see for most files, especially in an upload/download directory.

Can you say my answer?
I cant access this file…

sudo mkdir -p /etc/systemd/system/httpd.service.d
sudo tee /etc/systemd/system/httpd.service.d/custom.conf << EOF > /dev/null
[Service]
UMask=0
EOF
sudo systemctl daemon-reload
sudo systemctl restart httpd.service

linux - Setting the umask of the Apache user - Stack Overflow

I See:

Apache inherits its umask from its parent process (i.e. the process starting Apache); this should typically be the /etc/init.d/ script. So put a umask command in that script.

But where should I do put umask?