$_FILES always empty with ART PHP?

Support/Development for PHP
Moby
Forum User
Forum User
Posts: 7
Joined: Sat Oct 03, 2009 2:51 pm

$_FILES always empty with ART PHP?

Unread post by Moby »

Hello all:

I have some code that uses a html form with a type=FILE tag to post to a php form to upload files.

The code snippet works great on three systems - 2 with opensuse and 1 with Fedora. However, it does not work on the product system which is running PHP from ART. On that system, $_FILES is always empty in PHP.

I have gone through again and again and made sure that php.ini entries are correct (file uploads are enabled, max post and max upload sizes are set, upload tmp dir is set etc). I have tried this with PHP 5.2.9 and PHP 5.2.11 from ART.

Is anyone else seeing the same problem? or is anyone able to successfully use $_FILES in PHP from ART?

Thanks in advance for your help.
--Moby
Kalimari
Forum Regular
Forum Regular
Posts: 526
Joined: Wed Jan 02, 2008 3:21 pm
Location: United Kingdom

Re: $_FILES always empty with ART PHP?

Unread post by Kalimari »

Yup, use $_FILES with no issues on 20+ websites
User avatar
mikeshinn
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
Posts: 4155
Joined: Thu Feb 07, 2008 7:49 pm
Location: Chantilly, VA

Re: $_FILES always empty with ART PHP?

Unread post by mikeshinn »

Yeah, we've got tons of sites using $_FILES as well with no problems. Sounds like something else is going on, maybe a problem with cached code, or a bad module?
Moby
Forum User
Forum User
Posts: 7
Joined: Sat Oct 03, 2009 2:51 pm

Re: $_FILES always empty with ART PHP?

Unread post by Moby »

Thanks for the replies.
What really throws me off is that exactly the same piece of code (just a test .html and .php that is posted to) work perfectly fine on other non-ART systems.

If it is some bad cached code, would a restart of apache not clear out any cached code?

In case of a bad module, how would one being trying to figure out which module it is?

If anyone can help, I can put the test .html and .php up here together with the output of my phpinfo.

Many thanks again.
Kalimari
Forum Regular
Forum Regular
Posts: 526
Joined: Wed Jan 02, 2008 3:21 pm
Location: United Kingdom

Re: $_FILES always empty with ART PHP?

Unread post by Kalimari »

Does print_r( $_FILES ); have any output at all?
Is something like suhosin installed?
Is the php upload size limit being exceeded?
Output of phpinfo(); would answer the latter 2 (remember to remove anything that will specifically identify your server)
Moby
Forum User
Forum User
Posts: 7
Joined: Sat Oct 03, 2009 2:51 pm

Re: $_FILES always empty with ART PHP?

Unread post by Moby »

Thank you very much for your reply and time Kalimari.

Here is the information:

mob-test.html:
==============

<html>
<body>
<form method="POST"
action="./mob-test.php"
enctype="multipart/form-data">

<input type="hidden" name="MAX_FILE_SIZE" value="209715200">
<input type="file" name="imagedata"/>
<input type="hidden" name="_submit_check" value="1"/>
<input type="submit" value="submitit"/></form>
</form>
</body>
</html>


mob-test.php:
=============

<?php
echo "<pre>";
ini_set("display_startup_errors", "1");
ini_set("display_errors", "1");
error_reporting(E_ALL);
echo "Post:\n";
print_r($_POST);
echo "\n<br>FILES:<br>\n";
print_r($_FILES);
print_r($_SERVER);
echo $_FILES['imagedata']['tmp_name'];
error_log("test",3,"/tmp/testphp.log");
?>

Output of trying to upload 102.jpg via mob-test.html:
=====================================================

Post:
Array
(
[MAX_FILE_SIZE] => 209715200
[_submit_check] => 1
)


FILES:

Array
(
)
Array
(
[HTTP_ACCEPT] => */*
[HTTP_HOST] => lescoonline.com
[CONTENT_LENGTH] => 40
[CONTENT_TYPE] => application/x-www-form-urlencoded
[PATH] => /sbin:/usr/sbin:/bin:/usr/bin
[SERVER_SIGNATURE] =>
Apache/2.2.3 (Red Hat) Server at lescoonline.com Port 80


[SERVER_SOFTWARE] => Apache/2.2.3 (Red Hat)
[SERVER_NAME] => lescoonline.com
[SERVER_ADDR] => 70.32.92.132
[SERVER_PORT] => 80
[REMOTE_ADDR] => 70.32.92.132
[DOCUMENT_ROOT] => /var/www/vhosts/lescoonline.com/httpdocs
[SERVER_ADMIN] => request@g4creative.com
[SCRIPT_FILENAME] => /var/www/vhosts/lescoonline.com/httpdocs/beta/admin/mob-test.php
[REMOTE_PORT] => 51751
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => POST
[QUERY_STRING] =>
[REQUEST_URI] => /beta/admin/mob-test.php
[SCRIPT_NAME] => /beta/admin/mob-test.php
[PHP_SELF] => /beta/admin/mob-test.php
[REQUEST_TIME] => 1254763769
)


Notice: Undefined index: imagedata in /var/www/vhosts/lescoonline.com/httpdocs/beta/admin/mob-test.php on line 11


phpinfo output (partial):
===============
Configuration
PHP Core
Directive Local Value Master Value
allow_call_time_pass_reference Off Off
allow_url_fopen On On
allow_url_include Off Off
always_populate_raw_post_data Off Off
arg_separator.input & &
arg_separator.output & &
asp_tags Off Off
auto_append_file no value no value
auto_globals_jit On On
auto_prepend_file no value no value
browscap no value no value
default_charset no value no value
default_mimetype text/html text/html
define_syslog_variables Off Off
disable_classes no value no value
disable_functions no value no value
display_errors Off Off
display_startup_errors Off Off
doc_root no value no value
docref_ext no value no value
docref_root no value no value
enable_dl On On
error_append_string no value no value
error_log no value no value
error_prepend_string no value no value
error_reporting 6143 6143
expose_php On On
extension_dir /usr/lib/php/modules /usr/lib/php/modules
file_uploads On On
highlight.bg #FFFFFF #FFFFFF
highlight.comment #FF8000 #FF8000
highlight.default #0000BB #0000BB
highlight.html #000000 #000000
highlight.keyword #007700 #007700
highlight.string #DD0000 #DD0000
html_errors On On
ignore_repeated_errors Off Off
ignore_repeated_source Off Off
ignore_user_abort Off Off
implicit_flush Off Off
include_path .: .:
log_errors On On
log_errors_max_len 1024 1024
magic_quotes_gpc Off Off
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off
mail.force_extra_parameters no value no value
max_execution_time 300 30
max_input_nesting_level 64 64
max_input_time 200 60
memory_limit 32M 32M
open_basedir /var/www/vhosts/lescoonline.com/httpdocs:/tmp no value
output_buffering 4096 4096
output_handler no value no value
post_max_size 16M 32M
precision 14 14
realpath_cache_size 16K 16K
realpath_cache_ttl 120 120
register_argc_argv Off Off
register_globals On On
register_long_arrays Off Off
report_memleaks On On
report_zend_debug On On
safe_mode Off Off
safe_mode_exec_dir no value no value
safe_mode_gid Off Off
safe_mode_include_dir no value no value
sendmail_from no value no value
sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i
serialize_precision 100 100
short_open_tag On On
SMTP localhost localhost
smtp_port 25 25
sql.safe_mode Off Off
track_errors Off Off
unserialize_callback_func no value no value
upload_max_filesize 64M 64M
upload_tmp_dir /tmp /tmp
user_dir no value no value
variables_order EGPCS EGPCS
xmlrpc_error_number 0 0
xmlrpc_errors Off Off
y2k_compliance On On
zend.ze1_compatibility_mode Off Off

apache2handler
Apache Version Apache/2.2.3 (Red Hat)
Apache API Version 20051115
Server Administrator request@g4creative.com
Hostname:Port lescoonline.com:80
User/Group apache(48)/48
Max Requests Per Child: 4000 - Keep Alive: off - Max Per Connection: 100
Timeouts Connection: 20 - Keep-Alive: 15
Virtual Server Yes
Server Root /etc/httpd
Loaded Modules core prefork http_core mod_so mod_auth_basic mod_auth_digest mod_authn_file mod_authn_alias mod_authn_anon mod_authn_dbm mod_authn_default mod_authz_host mod_authz_user mod_authz_owner mod_authz_groupfile mod_authz_dbm mod_authz_default util_ldap mod_authnz_ldap mod_include mod_log_config mod_logio mod_env mod_ext_filter mod_mime_magic mod_expires mod_deflate mod_headers mod_usertrack mod_setenvif mod_mime mod_dav mod_status mod_autoindex mod_info mod_dav_fs mod_vhost_alias mod_negotiation mod_dir mod_actions mod_speling mod_userdir mod_alias mod_rewrite mod_proxy mod_proxy_balancer mod_proxy_ftp mod_proxy_http mod_proxy_connect mod_cache mod_suexec mod_disk_cache mod_file_cache mod_mem_cache mod_cgi mod_version mod_bw mod_fcgid mod_perl mod_php5 mod_proxy_ajp mod_python mod_ssl mod_dav_svn mod_authz_svn

Directive Local Value Master Value
engine 1 1
last_modified 0 0
xbithack 0 0

Apache Environment
Variable Value
HTTP_ACCEPT */*
HTTP_HOST lescoonline.com
PATH /sbin:/usr/sbin:/bin:/usr/bin
SERVER_SIGNATURE <address>Apache/2.2.3 (Red Hat) Server at lescoonline.com Port 80</address>
SERVER_SOFTWARE Apache/2.2.3 (Red Hat)
SERVER_NAME lescoonline.com
SERVER_ADDR 70.32.92.132
SERVER_PORT 80
REMOTE_ADDR 70.32.92.132
DOCUMENT_ROOT /var/www/vhosts/lescoonline.com/httpdocs
SERVER_ADMIN request@g4creative.com
SCRIPT_FILENAME /var/www/vhosts/lescoonline.com/httpdocs/beta/admin/test.php
REMOTE_PORT 53419
GATEWAY_INTERFACE CGI/1.1
SERVER_PROTOCOL HTTP/1.1
REQUEST_METHOD GET
QUERY_STRING no value
REQUEST_URI /beta/admin/test.php
SCRIPT_NAME /beta/admin/test.php


Thank you again for all your help, it is very much appreciated.
--Moby.
Kalimari
Forum Regular
Forum Regular
Posts: 526
Joined: Wed Jan 02, 2008 3:21 pm
Location: United Kingdom

Re: $_FILES always empty with ART PHP?

Unread post by Kalimari »

Your not exceeding upload limit etc, but I did notice 2 closing </form></form> tags in mob-test.html. Could that be the cause? It is obviously an environment/code issue of some sort, try to simplify things and work up from there. This code example shows $_FILES being populated on a couple of our systems:

Code: Select all

<html>
<head><title>Upload Test</title></head>
<body>
<?php
if( isset( $_POST['submit'] ) ) {
	if( $_FILES['file']['error'] > 0 ) {
		echo '<p>Error: ' . $_FILES['file']['error'] . '</p>';
	} else {
		echo '<p>Upload: ' . $_FILES['file']['name'] . '<br />';
		echo 'Type: ' . $_FILES['file']['type'] . '<br />';
		echo 'Size: ' . ($_FILES['file']['size'] / 1024) . ' Kb<br />';
		echo 'Stored in: ' . $_FILES['file']['tmp_name'] . '</p>';
	}
}
?>
<form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<p><input type="file" name="file" /></p>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
</body>
</html>
Moby
Forum User
Forum User
Posts: 7
Joined: Sat Oct 03, 2009 2:51 pm

Re: $_FILES always empty with ART PHP?

Unread post by Moby »

Thanks again Kalimari.
Fixing the </form> tag occurring twice did not fix the problem.
I ran your script and got the same problem, with $_FILES being empty, the output was:

Upload:
Type:
Size: 0 Kb
Stored in:
Kalimari
Forum Regular
Forum Regular
Posts: 526
Joined: Wed Jan 02, 2008 3:21 pm
Location: United Kingdom

Re: $_FILES always empty with ART PHP?

Unread post by Kalimari »

Your php settings seem OK for anything that might influence http uploads and the code supplied is as basic as php uploads get.
There must be something specific on the server in question. Have you compared php/apache settings between other correctly functioning servers?
Moby
Forum User
Forum User
Posts: 7
Joined: Sat Oct 03, 2009 2:51 pm

Re: $_FILES always empty with ART PHP?

Unread post by Moby »

Comparing the servers is a bit difficult. The production server is the only one running CentOS with Plesk and a bunch of vhosts. The demo and test servers where everything works are two openSuse boxes and one Fedora box.
Kalimari
Forum Regular
Forum Regular
Posts: 526
Joined: Wed Jan 02, 2008 3:21 pm
Location: United Kingdom

Re: $_FILES always empty with ART PHP?

Unread post by Kalimari »

That that would definitely highlight that it is an environment/setting which is the issue and not PHP/setting.

But it does seems as if file_uploads = off is set somewhere (OTHER than the php.ini). Plus, make sure you have permissions to write to the /tmp dir (check another setting is not changing it to a location other than set in php.ini)
Moby
Forum User
Forum User
Posts: 7
Joined: Sat Oct 03, 2009 2:51 pm

Re: $_FILES always empty with ART PHP?

Unread post by Moby »

Well, on the one hand, yes, given the nature of all that is on the server, I too would think it is some type of server environmental issue.

However, looking at all the output from phpinfo(), I can also be convinced that it is not an environmental issue, since effective settings of file uploads, file upload tmp dir etc are all "workable". I have made sure that the path that the tmp file upload dir setting in php is pointing to is chmod'ed 777 (at least for now) with no luck.

Today I am going to try and eliminate another thing that has been nagging at me, and make sure there are no application level reverse proxies or any other such hanky panky going on, though I doubt there is.

If an effective setting in phpinfo were to show up wrong or not show up at all, then yes, it would be the environment for sure - but what it driving my hair gray is that everything in phpinfo looks good :!:
Moby
Forum User
Forum User
Posts: 7
Joined: Sat Oct 03, 2009 2:51 pm

Re: $_FILES always empty with ART PHP?

Unread post by Moby »

The issue is resolved.
After yet once again carefully going through the Apache configuration, I noticed that while the IP address being used in the URL was one of many on the box but it was not one configured in Apache. Also the port being used int he URL was not even open on the server when looked at from the server (lsof). Using a different IP (was that was configured in Apache) and port that Apache was listening on, everything worked fine.
Not having physical access to the server (the server belongs to a client, but client colocates it and even the client has difficulty getting physical access!), my suspicions strongly center on some type of transparent (obviously not completely transparent) inline firewall/application-type proxy or firewall that was possibly interfering with file uploads.
Whatever it is, the issue is now resolved. Thank to all on here who helped.
--Moby
Post Reply