Reputation: 271
I'm running into an issue making a file upload form on a test site. Tutorials used:
In the first case, after creating the form and PHP file it would say that it failed to upload the file without any reason given (based on the code given, that's of no surprise). I then tried to redo it using the second tutorial and it gave me more information (a valid file has not been uploaded) even after I had modified the code so the only thing it checked at that IF gate was whether or not the size was too large.
I searched for a while and found that somebody recommended dumping $_FILES
, which gave an empty array. Somebody else recommended echoing $_FILES['userfile']['error']
, but that gave no information.
So I checked to make sure that the form had the right enctype (it does). Then I checked the PHP info from the cpanel. Uploading files is enabled and the max size is 2M (the stuff I attempted uploading was smaller than that).
I don't know where to go next to fix this. Any help would be greatly appreciated.
Upvotes: 0
Views: 4445
Reputation: 499
If changing any of the above parameters doesn't seem to make any difference, it can be that a html form somewhere contains the name MAX_FILE_SIZE as a hidden field.
<input type="hidden" name="MAX_FILE_SIZE" value="10000000">
In the example above, any file over 10MB will not be uploaded.
Upvotes: 0
Reputation: 8277
At the top of your script turn error reporting on pick the one that suits your needs from this list:
<?php
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>
Also check your error logs on your server for errors. :) This is the best way to most problems.
Upvotes: 1