I am using the script posted here by w3school for uploading files to a webserver. I am using Google chrome going to an Apache server with php7.
When I upload a file from my windows desktop the script works as advertised and the file is uploaded. However when I attempt to upload a file from any other folder the $_FILES variable is either not there or it's values are empty (It actually appears to be a size issue, see edit below). I'm not sure how to troubleshoot this as the devtools on chrome don't seem to give me any information about what it is sending in this POST message.
I am assuming the problem is on the client side as it appears the server is getting no information from the client.
EDIT
I am aware of how to look at the headers for requests and nothing about the file except for its content length are included in the header. There is no difference between the headers that work and those that don't except the content boundary, which appears to be random, and the content-length header, which obviously changes with the size of the file.
I had a thought that this was related to the size of the file, and it is. I have a folder of different size photos and I sorted and uploaded increasingly larger files until it failed. It worked fine until around 8M files, and fails when they are larger than 8,200KB.
I checked the php.ini and I have it set to a max upload size of 150M, so it's not the ini file. I also check all the logs and nothing other than the post request shows up when I try to upload the file.
I was able to find the answer here: why would $_FILES be empty when uploading files to PHP.
I did not know there was a post_max_size option in the php.ini file, which was set to 8M. Now that this is set to 100M. If you go over this size of a POST request php does not parse the POST information, thus giving you a blank $_FILES variable.
Related
I have a vps server (on hostinger) running on openlitespeed (cyberpanel). The website that I built uses PHP.
I created a file upload service and set my php config's post max limit to 1024M and upload max filesize to 1024M as well since both those settings work on my local when testing for large file uploads under 1gb. (I've also restarted php, as well as my server to see if it solved the issue but it still persists. I've also created a phpinfo file to confirm if my post max limit and upload max filesize were changed to 1024M/1G and they were changed)
But on my webserver, uploading files larger than 500mb gives me a "POST net::ERR_HTTP2_PROTOCOL_ERROR" on my console pointing to a line on one of my javascript code referring to my xhttp.send (specifically xhttp.send(formData) XML Http Request. This XML http request forwards the selected file to an upload.php script that processes the data. But it's not getting sent to that script due to the error.
When I get that error when uploading files larger than 500mb, I'd also get an error in my server's error log:
[NOTICE] [xxxx] [T0] [xx.xxx.xx.xxx:xxxxx:HTTP2-3#APVH_*:443_website.com] Request body size: <filesize> is too big!
The uploader works fine when uploading files under 500mb, it sends the formdata to the php upload script and stores it in the server as well as the database. But it gives an error when uploading more than that.
I've looked everywhere to solve this issue, I've also looked into openlitespeed's max request body size since it's seems like it's what the error on my error log shows, but most of the answers I've seen were from several years ago and no longer applies and didn't resolve the issue.
There doesn't seem to be any issue with my php script as well as my javascript from my tests since it works with no issues on my local server, and works fine with small file sizes on my web server.
Is there anyway to resolve this issue?
I have a site for media conversion where users can upload video, audio or image files and it is converted in to 3 popular formats. Conversion script works fine but I am having some issues with the tmp directory where the files get uploaded to. I have tried 2 scenarios I am fine with either but neither works and it seems to me to be permissions related but I can seem to fix the problem.
I am working locally right now while I work out the kinks.
Scenario 1:
File is uploaded to default local tmp directory (C:\WINDOWS\tmp) - works fine
Attempt to run conversion script using tmp file that was uploaded and it doesn't work - run from command line works perfectly fine though
Scenario 2:
File is uploaded to directory I have given IIS_IUSRS full control of (for testing) and file won't upload - yes the directory is spelt correctly (I changed the upload_tmp_dir value in php.ini)
Both the site the javascript that send the XMLHttpRequest to the PHP file, as well as the site the PHP file itself reside on are IIS sites so I assume the script is being run as IIS_IUSRS.
EDIT: Temp file is no longer being created at all for Scenario 1, can't figure out why I am assuming playing with permission messed something up because the code hasn't changed. I've given Modify to IIS_USRS and USERS to try and get it working again but no luck :( although the error log is still writing to the same folder...weird
NOTE: The "tmp_name" value of the $_FILES variable I am sending still has a value of "C:\WINDOWS\Temp\'filename'" but the file is not there
EDIT: Another new development, it appears it is NOT a permissions issue because I can create a temp file via $temp_file = tempnam(sys_get_temp_dir(), 'Test'); however it obviously does not contain the uploaded data so it does not solve my problem
PHP is ignoring the upload_tmp_dir because of one setting on APPLICATION POOLS.
It's not php-cgi.exe nor php.ini or a permissions issue.
Go to the application pool of the website experiencing the issue:
1. right click
2. select advanced settings
3. scroll to LOAD USER PROFILE and set it to FALSE.
that did the trick for me.
This is less of a problem solved and more of a workaround. The issue seems to be something with the
$_FILES['file']['tmp_name'];
When I echo the contents it looks as I expect however no file appears. So rather than taking advantage of that process that happens naturally, I have had to take a manual approach. What I have done is the following:
create a temp file
$temp_file = tempnam(ini_get('upload_tmp_dir'), 'php');
then add the content from the temp file created during the $_POST request. (which some how are in the $_FILES variable even though the file is not when I look in the directory)
file_put_contents($temp_file, file_get_contents($_FILES['file']['tmp_name']));
the I have my temporary file for processing.
I have a problem when attempting to upload really big files using PHP. I know this has been raised before and I have read many responses, but I have not found a definitive answer.
The basic code I use is posted here: http://design.wildsandwebdesign.co.uk/technical/uploading-files-2.php and I have used this with complete success for letting client upload image files, JPEG, GIF, png etc. The problem arose in allowing users to upload non-displayable files such as .psd files which can be very large.
In php.ini on both my local and remote servers upload_max_filesize and post_max_size are set to 128MB. The hidden field MAX_FILE_SIZE in the code has been set to various values during development. The problem is this: If the user selects a file bigger than the MAX_FILE_SIZE but smaller than 128MB,$_FILES['uploadfile']['error'] returns an error code of 2 as the PHP documentation says it will. If the file size exceeds 128MB then the upload handling fails altogether with bizarre results.
The “bizarre” results include irrelevant error messages such as “Undefined index: uploadbtn” this being the index of the submit button you have to click to get the error message(!) This happens with Firefox 26 and with Chrome. Bigger files can crash Firefox altogether which then displays the bug report dialog.
I don't want to upload files larger than 128MB, I just want to handle the situation where a user selects a very large file in some reasonable way. Does anyone know how to do this?
The production code is very much more complicated than the example above but I will happily provide it on request.
......
I built a website in that I upload 10 too big size(10MB) images. When uploading start, it continues to some time then a blank page will come. I tried to change php_values in .htaccess file, because I don't have permission to change the settings in php.ini file (it's shared server). I have some doubts regarding this.
1) what happen if file will going to post request, because I want fastly uploded the files.
2) it takes time when posting the request or uploding the file, I am cropping the images (loop) using php GD functions.
It is because of the limits your web hosting provider set. Which values did you try to change in the .htaccess?
You could try using some flash uploader, it should work despite the limits imposed by the server. A good one is SWFUpload.
That is because of the exection time of a script.You can edit your php.ini file. If that is not permitted you can set the *MAX_EXECUTION_TIME* for a script using your .htaccess file.
I have a site that is receiving 30-40k photo uploads a day and I've been seeing an issue pop up with more frequency now. This issue is this:
Our upload script receives (via $_FILES['name']['tmp_name']) a file (photo) that was NOT uploaded by the user & the majority of the time the file received is a "partial" upload.
Of course at first I thought it was my PHP code making a simple mistake and I've spent days looking over it to make sure, but after placing checks in the code I've found that the file received via a HTTP POST upload to PHP is actually the wrong file. So the issue is happening before it reaches my code. The tmp file (phpxxxx) received by the script is sometimes incorrect, as if it was somehow being overwritten by another process and its usually overwritten by a file that was partially uploaded.
Has anyone every seen an issue like this? Any help is greatly appreciated. I'm turning to this as a last resort after days of searching/asking other PHP devs
So to recap:
User uploads a photo
PHP script receives a file that was not uploaded by the user (pre code, via $_FILES in /var/tmp)
Usually the incorrect file received is a partial upload or a broken upload
It seems to happen randomly and not all the time
First off, check you PHP version.
Second, check your file upload limits and POST_MAX_SIZE in php.ini
It might just be that someone tries to upload a file that's too large :-)
Can you try different names for the temp file to avoid its being overwritten? Can you identify the origin of the new, incorrect and incomplete file?
Is this a development environment? Is it possible that more than one user is uploading files at the same time?
Try your program with very small images to check if SchizoDuckie is correct about filesize problems.
Try with different navigators to eliminate the admittedly remote possibility that it is a local problem.
Check permissions on the directory where the temp file is stored.
PHP's built-in file handling does not support partial uploads.
Turn off KeepAlives and/or send a 'Connection: close' header after each upload.
Configure your webserver to send the header 'Allow-Ranges: none'.