How to change uploaded file permissions for new files automatically - php

I recently moved a wordpress site from media temple's gs to their dedicated virtual server.
The file structure changed when I upload files. The permissions automatically upload as 644 and I'd like to change this. Where should I look to change this, the php.ini file or somewhere ont he server settings? It uses plesk.

You're going to want to find a way to change your umask. You might have to talk to your server administrator about it, if you don't have shell access.

Related

Wordpress: Uploaded file could not be moved - how to edit owner or similar?

After having created a Wordpress website on a test server, I moved it to the clients server. The website works as intended, but now I cannot upload files anymore via the Wordpress media area: I am getting a message "Uploaded file could not be moved to Uploads/.../..." (not sure about the exact English terms here, I use a different language)
Both "servers" are actually just webspaces at different providers - I have no access to the server configuration.
I saw this question and its answers. Now, when I simply set file permissions of the "uploads" folder and all its contents to "777", uploading is possible again, but as is mentioned everywhere, this should not be done for security reasons.
The remaining solution would be to check if the owner of the folder and files is correct. Probably not, but: Where do I see the owner (in an FTP program like Filezilla) and how can I change it? Or what else could I do to solve this problem with the very limited possibilies I have (basically just FTP access, no control over server settings)?
FWIW: Via FTP (Filezilla) I have no problem uploading files to that directory.
Just to let interested users know: I contacted the providers support, they gave me the advice to update the account to a higher PHP version (by putting two lines into .htaccess, which I didn't know was possible), and now the problem is gone - I can upload files again, with the regular 755 setting for file permissions on the "upload folder" and its subfolders.
(BTW: PHP was 5.2(!), now 7)

PHP file not working on hosting

So this is what's happening. I don't know how to explain this.
I made a software which uploads file to my website's FTP location. It's working as it should.
As you can see in the folder that inside public_html/phphostrot.rviews.xyz/user_rot/ there are 2 php files. But when i visit the url http://phphostrot.rviews.xyz/ i get a blank page with inder of / and nothing else. And if i try to access http://phphostrot.rviews.xyz/user_rot/ I get 404 error. Even the link to the file is not working. I don't know what's the problem.
I think it's a issue with the file permissions. Have you configured your server to serve files from your public directory.
Try changing the ownership of the files to www or apache
app, img, wp-admin, wp-content, wp-includes?
check file permissions (+x), as #atefth said, check owner.
check webserver config. and check apache/nginx logs

How to set file permission for linux host under windows?

For example, i want a file has permission of 644 automatically when i uploaded it to my linux host, before upload, it is under windows. How could i do this?
Btw, i use Filezilla for upload
Updated: Before post this question, actually, i ever thought it is impossible too. But, as i has many wordpress sites, i remembered that i never need to set permission for wordpress files. So i did an experiment,
dowload a new wordpress package, zip format (under windows)
uploaded it to my linux host,
unarchive
check permissions of these files
I saw all files had their permission naturely right, some 644, some 755, exactly as described in wordpress document
I think this is not possible in most cases.
Could you give more information on how you upload? FTP, SFTP, SMB? :-)
For example for FTP you could configure the FTP server in order to give all new files the 644 umask (see this example for ProFTPd).
For SFTP, the client might be able to change the permissions after the upload, because it has SSH access, after all.
You can't. The permission is not written in the file itself, but rather in the filesystem. So it has to be done once the file has being uploaded.
Assuming that you are using FTP to upload the files, better FTP clients (FileZilla) will allow you to set the permissions IF THE SERVER is setup to allow the FTP client to set it.
As far as "default settings", 644 is typically the default already for files. This again is set by the server. I would assume that there is an FTP client out there that will auto set it for every file, but I don't know for sure. If you go monkeying with permissions, remember that directories are 755, not 644, and it is possible that the server could let you remove your own access to the file.
First, what username owns the files? What username do you connect as when you upload?
What is that user's default umask setting?
So you could use the Windows FTP command "quote" which lets you send arbitrary commands to the FTP server.
Assuming your Linux FTP server supports SITE UMASK...
e.g. ftp> quote SITE UMASK 111
This would be equivalent to doing: chmod 666 * on the Linux command line but via FTP on Windows.

Problem with uploading files on root linux server

I have a plesk panel and root dedicated server on 1and1. I'm using custom programed php script to upload the files and create the folders to server. I have the upload folder named upload_data_folder with the 777 permission.
The scenario is the following:
I want to create folder in my upload_data_folder and than upload files in that newly crated folder. I'm doing this over php script so every file or folder that I create has apache user and the group as the owner.
I'm successfully crate the folder in my upload_data_folder and that folder is owned by apache, has apache as a group and has 777 premission. Then When I try to upload some files to that newly created folder It can't.
I think the problem is with some owner permission but if anyone has some idea what this can be I would be very grateful
It was my custom made script. huuu I solved the problem. The php safe mode was turned on. After I turned it off everything works perfectly.
By default apache document root is /var/www/html/. If plesk is installed document root will have a path like:/var/www/httpdocs for non-secure sites. Thus secure sites are stored in /var/www/httpsdocs.

Permissions problem when uploading images using PHP in IIS

We have just moved a website to a new server, both servers are Windows Server 2003 running IIS as the web server.
When uploading images we require that the uploaded files have certain permissions for the NETWORK SERVICE account. Images are uploaded using PHP, they are then filtered by ImageMagick using the mogrify.exe binary for resizing purposes and placed in a new folder created by PHP.
The problem we are encountering is that the uploaded file does not inherit the NETWORK SERVICE permissions although the folder does.
I ran filemon to see any errors and get the following:
mogrify.exe:6396 OPEN C:\inetpub\wwwroot\example.com\data\334480\test.jpg ACCESS DENIED NT AUTHORITY\NETWORK SERVICE
The reason we require NETWORK SERVICE access is due to an ASP.NET script we use to resize the image on the fly. I've searched Google but cannot find a solution. Any ideas?
Managed to fix the issue, I changed the upload tmp dir in php.ini to C:\Test and gave Test the permissions I required, I had already made this change but on further inspection upload_tmp_dir is set twice in the php.ini file. Uploaded files inherit the permissions of the temporary directory.
Have you made sure the "NETWORK SERVICE" ACL applies to "This folder, sub-folders and files", wherever it is applied. Also, try making a new folder somewhere else with that same ACL and see if files created by PHP inherit the permission.

Categories