I have an issue in a program that uploads files from html in my local server, into the /var/www/html/my_app directory.
In this directory I have changed the permission with:
sudo chmod -R 777
So I can save the photo that uploads in the directory inside my_app.
But here is the problem, when I upload a file inside the directory it always has the read permission.
Can I change that? So all the files I upload have permission.
chmod 777
move_uploaded-file always set permission to 600 for any uploaded file whatever configuration set in apache umask. you can use chmod in context with your code while uploading file and set permission.
chmod($target_path, 0664);
http://php.net/manual/en/function.move-uploaded-file.php In the comment section another users have same issue so they are describing same thing.
Related
When I upload files through my cpanels file manager all my php file permissions are being changed to 0666 from what I read this is not secure + it is causing my WordPress to not function correctly. Normally web hosts have the permissions set to 0644 when uploading files. It would takes ages for me to change all files manually from 0666 to 0644. How can I change the permissions when I upload in cpanel? Should I try ftp and see if that makes a difference?
EDIT
When I upload the zip file it uploads as 0644 than when I extract the files inside are all turned into 0666.
Thanks
There is no need for you to re-upload all files to simply change permission for them.
Use your FTP client to change file permissions for files, directories and sub-directories.
You can do this via command-line SSH (if you have access).
I have my files uploaded on Ubuntu server. Everything is working except file upload.
I have given the permission to all the files as 0644 and for the folders 0755.
As per the references i am supposed to change the folder permission to 0777 which i don't want to do.
Is there any other way to enable file upload on ubuntu server without changing the permission from 0755 to 0777 ?
Don't apply 777 permission to any of your files/folders in the server.
The files are not uploading mainly because of two reasons.
Incorrect ownership (user:group)
Incorrect upload path
This article will help to setup the proper file/folder ownership.
I hope this helps.
I want to know that if we set the 777 permission on a folder to upload filed, do we need to set the permission of internal folders as well or it will work inside the external folder for which we have set the permission
exp.
images/newfolder
if we set the permission of images, newfolder will allow uploading files automatically or not?
Actually the answer is no. Setting 777 permissions on a folder does not guarantee that all sub folders are also having the permission 777. Unless you do that recursively. So check which OS you use and do that recursively. I use linux (Ubuntu) and I can do this
sudo chmod -R 777 /path/to/dir/
I know this was brought up many times. Still I can not find a sutable answer.
I want to upload a file to a server and want to set temporary 777 permission to the file where I put content. I am the only owner of the file and the directory and it does not seem to be an option to change or add an owner from the control panel and I dont want to set 777 to that folder. Since neither apache nor script own the file chmod does not work. Is there a way to get the ownership to php, a particular script or the server throught chown function? The script that POST a file is not publically accessible btw.
Thanks.
Dunno if I am right or not.
First you can get the owner of the file with this
$filename = 'index.php';
print_r(posix_getpwuid(fileowner($filename)));
with
chmod('/var/www/folder/', 0777)
chmod('/var/www/folder/index.php', 0777)
you can change any folder or file to 0777
you can also check with chmod the file or folder have
if( chmod($path, 0777) ) {
chmod($path, 0755);
}
I have an uploads directory on my server, php upload works fine when folder's permission is set to 755 but if I make new dir inside uploads (uploads/subuploaddir) upload fails and I need to set 755 permission for this folder manually, so my question is how can I set 755 permission for uploads dir and all of it's future created sub directories?
PS. chmod -R 755 ...mypath/uploads doesn't work
Thanks in advance.
All answers are very appreciated.
Peter
UPDATE:
Problem solved, my fault. PHP creates folders with permission 777 as default and I created folders for testing purposes through FTP manually, so it was created by another system user and with different permission.
Use
umask(022);
in PHP before creating a file (e.g. line 1 in index.php). Using that option, every files that PHP creates will have a permission that equals to 755. If that doesn't work, search your code for calls to umask and change them to the one above.
you can use this command
chmod -R 755 directorypath or file