My PHP upload file code is generating an error, randomly, after I changed NOTHING about the code. I did edit the PHP.ini file... but then I changed it back and now my file upload system is broken for no reason. I've simplified the error generated to this example:
$count =0;
foreach ($_FILES['file']['name'] as $filename){
echo ($_FILES["file"]["error"][$count]);
$count+=1;
}
is producing "1" as an error for a valid file. If I knew what "1" meant, I think I'd be able to fix the issue. How can I determine what the error is? As I mentioned, I have changed absolutely nothing about the code, which was working a minute ago and is now not working.
Alright, I should have mentioned this but for people in the future freaking out about multiple file uploads, I'll mention it now. I am using GoDaddy and shared hosting accounts dont have access to some of the filepaths/commands people would normally use with SSH, so SSH is worthless. In GoDaddy though, in CPanel, under Software, there's an option to kill processes. I did this and my PHP script worked with edited PHP.ini. Thanks to everyone for leading me in the right direction – user2954658
Related
I have a VB.NET software that uploads files using an HTTP request to PHP. This worked fine until May but now it fails when uploading files over 65KB. I can not tell when it stops to work exactly. Even though, I don't think it is relevant. So to be clear, uploading a file under 65KB works correctly.
I looked with my hoster and he doesn't see any error neither do I on the server (the part I have access). VB.NET doesn't give me a pertinent error, but using WireShark, I've been able to get either a 500 or a 400 error. But it didn't give me clues on what is failing.
I verified this question which is not solved, though the things said there are OK on the server too.
PHP not uploading file over 55 kb
I have another option to fix it: splitting my files in chunks of 50KB and rejoining them via PHP. Though, I rather understand what is happening because this can happen again even with chunks of 50KB.
Server is Apache/2.4.28 (Unix)
EDIT 1
I have new conditions: I now have my own server running on Windows + Apache 2.4 + PHP 5.6.
Now it goes a little farther. I have an error when using move_uploaded_file function that gives me: Error #3: The uploaded file was only partially uploaded. It is coherent with the file being stopped to be sent near the end. So I now receive an HTTP 200 response but a failure after ward even though I suspect not being there.
I can certify I did not stop my VB.NET software that is uploading the file.
I tested changing KeepAlive to Off/False on both sides. No luck :(
Tried to add header ("Connection: close"); in my main file (that is used for all transactions with this VB.NET software). No luck.
Even though, it is not currently an issue, I changed (PHP configs) the upload_max_filesize to 256M and post_max_size to 300M (because it will be a problem if a can figure out this one).
I got those suggestions from : https://wordpress.stackexchange.com/questions/176465/failed-media-upload-the-uploaded-file-was-only-partially-uploaded
The only one I could not try is replacing an apache/php module which doesn't seem to exist on Windows.
Depending on your server's configuration, when an error 500 is returned an error_log is written. The problem is with the error 400. Which according to wikipedia's list of HTTP codes is actually a BAD REQUEST. Some output from your error_log when the attempt is being made might put us in the right direction.
EDIT: The phpinfo() output that I direct you to below, shows display_errors off but that is overridden in a Wordpress configuration file --- I think. At least I'm seeing PHP errors so I assume it is overridden.
But, as it goes, when you assume you make an ass out of you and me. I'll change it in the php.ini file and report the results in another edit.
EDIT: I set display_errors On and display_startup_errors On and produced the errors again and the cgi_error_log is still empty.
Original questions beings below ------------------------
This is pretty elementary but I'm having a problem and I'm unable to get my brain out of first gear today and I'm in need of a reality check.
I wanted to empty the cgi_error_log file and tried to replace it with an empty file via FileZilla. FileZilla reported it was uploaded but when I looked on the server, it had not been replaced.
I finally used the hosting company's File Manager and deleted the file and uploaded an empty file. That succeeded and now the cgi_error_log is empty - it has been since I uploaded the empty file December 14, 2015 at 1941 (local time).
I expected something to have been logged by now.
One of the last messages in the cgi_error_log before I deleted in and uploaded an empty file, was:
20151214T181242: www.example.com/index.php
Failed loading /usr/local/lib/ioncube/ioncube_loader_lin_5.2.so: /usr/local/lib/ioncube/ioncube_loader_lin_5.2.so: wrong ELF class: ELFCLASS32
Failed loading /usr/local/Zend/lib/ZendExtensionManager.so: /usr/local/Zend/lib/ZendExtensionManager.so: wrong ELF class: ELFCLASS32
I changed the actual URL,l in the message, to www.example.com etc, as is standard here.
Don't worry about why the error occurred, I already asked a question about that issue, got a reply, and am now waiting on my hosting company to respond to service ticket I submitted about it.
I have not changed the file that was producing the above error and thus, I would expect errors of that type to be occurring and be logged to the cgi_error_log file.
My problem right now is that nothing is in the cgi_error_log file and I'm wondering about permissions and such on the file. I submitted a service ticket about this but got the usual uninformed responds.
This my question here as a reality check. If PHP errors should be written to cgi_error_log, then something is wrong. If not, I try a different approach to determine why the cgi_error_log is still empty.
The server is running Apache.
If you want to see the output of phpinfo(), look at this file.
Assume the following error (I forced it to occur with 1/0;):
Warning: Division by zero in /hermes/bosoraweb081/b1107/myd.sugarcatsimon/public_html/pdmeoff/pdroot/welg/wp-content/themes/thingspissed/functions.php on line 3
and, this one I caused by simply typing "This will cause an error" in a PHP function:
Parse error: syntax error, unexpected 'will' (T_STRING) in /hermes/bosoraweb081/b1107/myd.sugarcatsimon/public_html/pdmeoff/pdroot/welg/wp-content/themes/thingspissed/functions.php on line 3
I know that I'm asking more than one question, below, but they are all about the same matter - what and where is logged for PHP errors.
1) Should those be logged to a file?
2) If so, are they logged to cgi_error_log or some other file?
3) If it is not cgi_error_log, where would they be written?
4)What type of errors, if not PHP, are written to cgi_error_log?
5) How can I cause a message, of any type, to be written to cgi_error_log, besides using the error_log() function?
If I don't get it all in gear, I'm going to drop my brain off at the repair shop and have them give it a good overhaul.
Thanks in advance.
The cgi_error_log replacement had the wrong permissions. It was 644 and should have been 664.
For future searches - The cgi_error_log file needs to have permissions set to 664 for logging to succeed.
Well, this is a problem I have never seen before.
I am trying to stream an FTP file using PHP's fopen() and feof() in order to copy it from one server to my own. This works fine when using normal http:// URLs. However, when using the ftp:// protocol, I'm receiving the following error:
fopen(ftp://.../streaming/planted2.mp4) [0function.fopen0]: failed to open stream: FTP server reports 550 /streaming/planted2.mp4: not a plain file.
Bear in mind that I have confirmed the URL is correct.
If I pop it into my browser's search bar, it always loads correctly.
Following this error, any attempt to use feof() or fread() on the wrapper results in an error complaining that the respective function expects a resource, but that instead a boolean is being provided. This would not be the case if fopen() was not failing.
As the files are quite large (several gigabytes at times) streaming is mandatory. Also, due to the configuration of the server, I need a way to loop through each chunk in order to buffer some output. If I don't, the server holds up. It's a weird configuration on Rackspace's behalf. That's why I'm using feof().
So, without further ado, my question is this: What does the 550 error mean, and what is a "plain file"? If it is a problem with the configuration of the server I am attempting to download from, what are my options, given my limitations?
EDIT
I have determined this is a server issue. However, the problem is still unresolved.
I contacted my boss and our server administrator, and the server guy told me to test this out on a different Windows-based server instead of the Linux-based one I was playing with. My script works with the Windows server, so I have confirmed my script is not in error.
Unfortunately, my boss still wants me to figure out the problem, and find out why it's not working on the Linux box. I have absolutely no idea why, and don't know where to look. Any hints would be greatly appreciated!
I've just come across this issue when trying to get a file from a sco unix server.
Server File Location: /home/user/data/myfile.csv
I can put the below into any browser and it gets the file.
ftp://user:password#host/data/myfile.csv
However if I run the below, I get the same error as you
$f = fopen("ftp://user:password#host/data/myfile.csv", "r");
However, if I put the full path into fopen - it works fine.
$f = fopen("ftp://user:password#host/home/user/data/myfile.csv", "r");
I'm not sure if this will fix it for you, but works for me.
I have a DMZ set up with a web server and an application server, both running Ubuntu under gnome (v11.04 on the web server and v11.10 on the application server). session_start() has started hanging on the application server. The code is located on the application server and it does not hang when I access my web site and access the page with the session_start() call on it. It seems that every session_start() has started hanging on the application server although I have no problems with the associated pages when I access them from other computers or across the web. Also I have only just started having this problem on the application server without having made any changes to my php code. Could it be that some buffer has filled up and needs to be cleared?
I tried editing /etc/php5/apache2/php.ini and setting
session.save_path = "/tmp"
/tmp exists.
But I still have the problem. I can stop it hanging by preceding session_start() with session_end() but then it does not execute the remaining PHP or html code in the file.
/var/log/apache2/error.log included the following message:
PHP Notice: A session had already been started - ignoring session_start() in
/var/www/DraculaPgm.php on line 101, referer:
http://MyWebSite.com/ApplicationServer/Dracula.php
Any assistance with this would be greatly appreciated,
Peter.
Update 29-Dec-2012
Thank you to everyone who replied to this question. Unfortunately, I tried all of the suggestions and 'session_start()' still hangs. However, if I leave it for a few minutes, it breaks with the following error message.
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /ApplicationServer/Dracula.php.
Reason: Error reading from remote server
Apache/2.2.17 (Ubuntu) Server at MyWebSite.com Port 80
I have squid installed on the web server. Could this be a problem?
Thanks,
Peter
This sounds like a configuration issue. Make sure that PHP is reporting all errors, i.e., error_reporting(E_ALL) and either display or log all errors. (You might even want to enable display_startup_errors in your php.ini) - reporting all errors may shed light on what's going on. (if you need help you can post any errors that you get from this as an edit) You may want to look at the following as well for troubleshooting the issues with sessions:
When using /dev/random as session entropy file
When page is calling itself with the same session
Alternatively if none of those show anything you may want to read over the bug report at https://bugs.php.net/bug.php?id=28856&edit=1 depending on what version of PHP you are running.
I changed 'session_start()' to the following block.
if(!isset($_SESSION))
{
session_destroy();
session_start();
}
I now do not have the problem. I am hesitant to say that it fixed the problem since it did not seem to fix it right away.
Thank you to everyone for your help,
Peter.
Try changing the permission of the /tmp folder by doing chmod 777 /tmp and check if its working.If its working then change the permission mode to make it more secure
Try checking out this Question I call session_start() the script hangs and nothing happens
And this http://www.projectpier.org/node/1934
"It seems that the session file is opened exclusively. On some
occasions (Windows) I have found that the file lock is not released
properly for whatever reason, therefore causing session_start() to
hang infinitely on any future script executions. My way round this
problem was to use session_set_save_handler() and make sure the write
function used fopen($file, 'w') instead of fopen($file, 'x')"
You can find many others having the same problem and their workarounds if you go through http://php.net/manual/en/function.session-start.php
if(!isset($_SESSION))
{
session_start();
}
Use this at the top of your PHP file!
And for your info: session_destroy() is used to end session.
Before anything else - try another browser!
I just encountered this session_start problem. I checked my tmp folder and everything and I was about to call my hosting-provider until I thought I should try another browser first because it might have to do with session cookies.
I work with chrome, so I tested in IE and found that it was indeed the case: It worked in another browser!
I closed IE ;) - went back to chrome, looked for the cookie (PHP_SESS_ID), deleted it and everything works again!
Well, the good part is - Just like you guys I got to brush up my knowledge of -jay- sessions! ;)
I am having some strange issues with mysqli connections.
I was working on a page with mysqli, and it has been working fine all day. I then made a copy of this page, and stripped it down to debug a problem, and tested it as a different file. It worked fine connection wise. Upon trying to request the original file I was working on, I get the error:
Access denied for user 'user'#'localhost' (using password: YES)
I don't understand why. I have closed the connections after I have finished using them each time, although I don't see why that would be an issue. Interestingly, an older version of the file works fine, despite containing the exact same connection details and code.
What is going on?
Turn the question around. Rather than saying the two versions (the one that works and the one that doesn't) are identical in the aspects that matter, focus on the ways in which they are different and try to isolate which difference(s) also matter.
Make an additional copy of the working version. Verify that it works. Try making it into a copy of the non-working version by applying as many of the changes as you can, one by one, to this test copy, until you have something that is as close as possible to the broken version but that still works. Compare these two, and that should show you where the problem is.
Weird. If you are testing files from the same machine they should be working (if they have same code).
Check again username & password, i.e. spaces or strange chars.
Just for the sake of it, run a diff between the working copy and older version of the file. Check for any issues like: moved brackets, variable name changes, etc. Maybe the part of the code that defines the username and password never gets run!
If you need a free program for that, check WinDiff
If you put:
error_reporting(E_ALL);
as the first line in your code do you get any errors on either page? There may be something strange like the program can't open an include file anymore.
You said copying File A to File B means File A doesn't work. What happens if you copy File A to File B, delete File A then copy File B to File A?
Ensure that your IP is added to the MySQL allowed connections list, also ensure your password is correct. Try providing a full hostname rather than localhost if possible.
Post your code if un-successful.