Read permission issue with moved uploaded files on IIS - php

I have a PHP 5.4 served website on a Plesk-based IIS 7.5 server. The app pool identity runs as IWAM_plesk but PHP runs as IUSR_username.
When I upload files, PHP can move the file and create a thumbnail from it, but the file doesn't gain the anonymous IWAM_plesk(default) permissions for browsers to read the file and thus the image (not the generated thumbnail) "cannot be read" when viewing the site.
How can I grant the correct permissions to the file after uploading?
Only a folder "replace permissions on all child objects" fixes the issue (or adding the user permissions directly to the file).

This is a problem of the upload_tmp_dir setting in php.ini. When moving a file during the upload process, the permission don't move with it. Create a project specific upload folder, set the users/groups as you need it and set this folder as upload_tmp_dir, either in php.ini or project specific.
The uploaded file will inherit the permissions of the folder.
Had this problem with the webplatform installer, which sets the upload_tmp_dir to C:\Windows\temp by default.

Related

PHP-uploaded file has incorrect permissions

I'm using PHP to allow a user to upload a file. The file is being uploaded, but the permissions on the file are incorrect. I set up the permissions on the folder and checked the box that says apply to all children in the folder.
This works only after I make one change to the newly uploaded file. If I don't make a change to the permissions, it gets this default set that breaks the rest of my application.
For example, C:\uploads\ is set to allow users in the group "Everyone" to read and write. This however doesn't apply to the newly uploaded file until I do something to that specific file's permissions (add or remove any user or group to its permissions - this change gets overwritten by the folder's permissions).
This is on IIS6 (I believe) on Windows Server 2003
Windows upload file to temp directory and then move it with temp directory permissions. If You give good permissions to the user on this folder (upload_tmp_dir) then will be no problem.
You can also use windows system command:
CACLS or ICACLS
Do:
chmod()
On Your file after upload

Security risk in setting PHP file permissions to full

I'm running XAMPP on Ubuntu, and I copied the lampp folder to /opt/. I also downloaded CodeIgniter to htdocs/, and created and modified some files in it, including changing their permissions. Are there files in CodeIgniter that I shouldn't set permission to full, because maybe then once I upload them onto a server anyone can see their contents?
Ideally, your CodeIgniter should be setup such that the application and system folder lie outside your document root. Only the index.php file along with any assets (images, javascript, css etc.) should lie within the document root.
As for file permissions, 755 works fine. There's no need for full permissions 777.

Why can't I download files uploaded with PHP?

I have created a custom CMS with PHP and it uploads files to a directory with 777 permissions on it. When the files are uploaded they are given 600 with apache being the owner, therefore I can't download them through FTP as the main FTP user.
Anybody have any ideas? I have tried changing the permission but don't have rights due to the owner being apache.
You cant chmod the files, but 'apache' can: after uploading an moving the file,change the permissions in the same script. As it is run by apache, it is allowed to do so.
http://php.net/manual/en/function.chmod.php
For uploading files it is important to note that uploading files without explicitly setting permissions after is a bad practice.
I would take the link Nanne provided and begin to add that to your upload script. This will ensure that the files are given the appropriate permissions for each situation you will need them.

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