Sign in to follow this  
hplus0603

[web] _FILES doesn't contain my file (PHP 5 and Apache 2)

Recommended Posts

hplus0603    11356
I have a form that looks something like:
<form enctype="multipart/form-data" method="post">
  <input type='hidden' name='issue' value='06march'/><br/>
  <input type="file" name='picture' size='45'/><br/>
  <input type='text' size='40' name='caption'/><br/>
  <input type='submit' name='upload' value='Upload'/>  
  <input type='submit' name='cancel' value='Cancel'/>
</form>
I have a PHP script that looks something like:
  if( gpc( 'upload' ) ) {
    print( "_FILES: " ); print_r( $_FILES ); print( "<br/>\n" );
    print( "_POST: " ); print_r( $_POST ); print( "<br/>\n" );
    $tmp_name = $_FILES['picture']['tmp_name'];
    if( !is_uploaded_file( $tmp_name ) ) {
      error( "'$tmp_name' is not an uploaded file." );
    }
(The function gpc() just tries to get the argument from all three argument sources in order) When I browse to a file and try to upload it, it prints the following:
_FILES: Array ( )
_POST: Array ( [issue] => 06march [caption] => [upload] => Upload )

Notice: Undefined index: picture in 
/var/apache/htdocs/default/RPNS/upload/uploadpicture.php on line 18

Error: '' is not an uploaded file.
I have looked at the data sent from the browser with Ethereal, and it's sending the file alright (with a filename= attribute and everything). However, it doesn't show up in _FILES. My php.ini claims that max file size is 4000000, and file upload is enabled. Apache log doesn't show any errors (it shows up as a POST in access_log). Syslog does not show any errors. This happens both with Firefox and IE. What am I doing wrong? What more should I check?

Share this post


Link to post
Share on other sites
markr    1692
Sounds like it's definitely a server problem.

Have a look at your PHP error log (you do have one, right?) - make sure error_reporting(E_ALL) is set.

You've done all the right things to get this to work. I suppose one possibility is that the temp directory it keeps uploaded files in isn't writeable - but I'd expect PHP to throw at least a warning in that case.

Mark

Share this post


Link to post
Share on other sites
hplus0603    11356
Error logging is set to E_ALL; error reporting is set to both HTML output and syslog. Neither shows a problem.

post_max_size is 8 MB, memory_limit is set to 16 MB, max upload size is 4000000, the file I'm uploading is about 60k. My Apache doesn't have a LimitRequestSize set.

I've done file uploads before, and it's worked, so I can't figure out what's wrong now. Nothing seems different. Frustration is mounting.

Share this post


Link to post
Share on other sites
Kylotan    10007
Is it practical to do the form submission on the command line? That way you could perhaps feed it to PHP directly and at least narrow down whether it's PHP or Apache that's misbehaving.

Share this post


Link to post
Share on other sites
hplus0603    11356
I got the latest Apache and PHP sources and did a full re-build, and it seems to give me the right data now. Weird, given that I've been running this install until now for longer than I should have ;-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this