PHP can't open uploaded files - php

I have Ubuntu Server with lamp.
When i uploading files like xls or images it works fine, but when I trying to open it says me that the Excel file was broken. Same thing happens with images
Is it possible that php changes the file?
Permissions for /var/www/publick_html/uploads is 777

well, I know,I use windows and maybe this is extremely OFF TOPIC, but I have a simililar problem with uploaded files and my experience can be usefull for other people.
In my case, the uploaded file can not be open because it was written first in
C:\Windows\Temp
and then moved to the upload directory, but my temp folder doesn t have permission to access to it. Infact, if I click on temp folder I see:
After I clicked "Continue", the problem has been solved!

The problem was in versions of apache and php.
Version of apache was 2.2 and php was 5.4
I upgraded my apache to 2.4 version and now it works fine.

This should solve your problem with being unable to open uploaded files with PHP on SQL SERVER. It solved mine.
You may come across the following problem using PHP on Microsoft IIS: getting permission denied errors from the move_uploaded_file function even when all the folder permissions seem correct. I had to set the following to get it to work:
Write permissions on the the folder through the IIS management console.
Write permissions to IUSR_'server' in the folder's security settings.
Write permissions to "Domain Users" in the folder's security settings.
The third setting was required because my application itself lives in a secure folder - using authentication (either Basic or Windows Integrated) to identify the users. When the uploads happen IIS seems to be checking that these users have write access to the folder, not just whether the web server (IUSR_'server') has access.
Also, remember to set "Execute Permissions" to "None" in the IIS management console, so that people can't upload a script file and then run it. (Other checks of the uploaded file are recommended as well but 'Execute None' is a good start.)
reference https://www.php.net/manual/en/features.file-upload.php

Related

Missing Temporary Folder in WordPress (PHP 5.6) on IIS, Windows Server 2012 R2

I am helping out with a WordPress site which is hosted on IIS on Windows Server 2012 R2, running PHP 5.6
(don't ask - and please don't snark - this is a website for my local church)
For some reason I keep getting "Missing Temporary Folder" everytime someone tries to upload any media files.
I have tried creating a "temp" folder in the "wp-content" folder.
I have also reset all permissions on the ENTIRE wp-content folder, removing any "read-only" locks and granting all users "full control" (yes - I'm getting this desperate to just get the dang thing working at this point!)
In the wp-config.php I've specified my temp directory.
(this used to be a relative path, but I've switched to an absolute path, just to rule out the virtual directory in IIS confusing things)
define('WP_TEMP_DIR', 'C:\inetpub\wwwroot\wp_church\wp-content\temp');
In my PHP.ini (in the installation folder for PHP) I defined:
upload_tmp_dir = C:\wpupload
I created that folder, and again gave all users full control.
I have since rebooted the server and run IISRESET numerous times.
But every time I try uploading a media file I still get the error message:
Missing Temporary Folder
Can anyone help???
Please?
Ok sorry about this.
it would appear that "upload_tmp_dir" is declared TWICE in the php.ini file.
I found another one right at the very bottom. I changed that .. all fixed!!

Permission Denied on move_uploaded_file to another server in IIS

I have a PHP web application running on IIS, which allows a user to upload a file from a simple html form. The uploaded file is then moved to a folder on another server. This is working correctly on Apache, but fails on IIS with the error:
function['move_uploaded_file']failed to open stream: Permission denied
in...
I've checked all the permissions on the directories. If I run a simple PHP script through the command line to copy a file from the server into the folder on the other server it works correctly, so I suspect the problem is with IIS.
if (move_uploaded_file($_FILES ["file"] ["tmp_name"], "\\\\000.00.0.00\\tia\\web\\upload\\" .$_FILES["file"]["name"])) {
This has been covered already here. Quoting the reason here:
You have mapped target directory to a share such as \server2\files. These mappings are only available to the current users (eg, the admin account), not to the IUSR account that your php is probably running as (assuming IIS). Solution, don't use mappings, instead use the full 'unc' path name, ie '\server\share\folder\file.ext', also remember that the IUSR account will need access to these shares/folders/files
From what I can see in your comment, you are using a \\ prefixed network share as the target for your move_uploaded_file() operation.
I'll bet a beer that PHP isn't allowed to access that share. Remember, PHP runs with IIS's permissions!
Try saving to a local, globally writable path first. If that works, you know you have to fix the share's permissions.

php move_uploaded_file not working on Windows 7 only

I've got a project that I am setting up file uploads for. The project is in Zend, but I am using PHP's $_FILES array and move_uploaded_file to save the files. This was working perfectly on my Windows Vista computer but won't save the file on Windows 7.
It creates a new folder for every upload no problem, but won't save the file and gives no error message. It is the same exact code as the other computer (grabbed from source control) and both are using PHP 5 with WAMP server. Any ideas why the Windows 7 computer won't save? I even added Full Control to 'Everyone' for the uploads folders.
In Windows 7:
Go to this location -> C:\Windows\Temp
Windows will ask permission- > press go or confirm or yes
then try again to upload files
finish
if your saving the files in the system drive, you might have a problem due to its security.. try to transfer your WAMP and PHP in other local drives. but if you insist to have it in your system file. just try to work around with its security.. Good Luck!
When you create the folder you want to move it to, are you setting the permissions in php? When I switched to windows 7 I had the same problem and setting the permissions solved it for me.
mkdir("/path/to/your/dir", 0777);
I read that chmod is ignore by windows on the php.net > mode reference. I was not able to mkdir on windows 7 by using mkdir /path/to/directory or path\to\directory\. I also tried editing the permissions for the parent (root?) directory I was using for the new folder. No solutions found here, yet. The folder reverts to read-only after unchecking the box on the folder settings though so maybe that is part of it

401 error on iis when uploading files via PHP

I have an upload script that runs on a windows webserver 2008. The uploads works nice, the file is created on the server. But when I try to access the uploaded image file via http, I just get an error 401. How can I resolve this?
EDIT: setting the chmod to 0777 after the file has been uploaded did not help, too.
That did it: https://serverfault.com/questions/85983/iis-iusrs-cannot-access-files-uploaded-and-created-by-network-service-error-401/229151#229151
For security reasons, many websites sequester uploaded files until they are validated, at which time they are made publicly accessible. If this is the cause, you'd have to ask the site's administration.
So to summarize : one of the solutions is :
Edit "upload_tmp_dir" inside of php.ini and for example set to "C:\my_temp_folder"
Than right click to folder and security tab than give modify permission to the IUSRS user ;)

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