tags:

views:

178

answers:

1

Hello, I'm using class.upload.php to upload pictures onto the server. Here is my form:

<form action="<?="http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];?&gt;" method="post" enctype="multipart/form-data">
  <table style="width: 100%; padding-top: 20px;">
    <tr>
        <td>Image file:</td>
        <td><input type="file" name="image_file" /></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td align="right"><input type="submit" name="add_new" value="Add image" /><td></td>
    </tr>
</table>
</form>

In php code I do:

if( array_key_exists('add_new', $_POST) )
{
    echo 'add new is in array';

    echo '<pre>';
    print_r($_POST);
    print_r($_FILES);
    echo '</pre>';

    $handle = new Upload($_FILES['image_file']);
    ...
}

Here is an output of print_r:

Array
(
    [image_file] => somefile.png
    [add_new] => Add image
)
Array
(
)

As you can see second array is empty ($_FILES), so image doesn't upload. Why?


  • operating system : Linux
  • PHP version : 5.2.12
  • GD version : 2.0.34
  • supported image types : png jpg gif bmp
  • open_basedir : /home/httpd/vhosts/%site%/httpdocs:/tmp
+1  A: 

Have you tried with images smaller than the post_max_size ini setting? Also, make sure your /tmp has space and is writable.

Other resources:

1) Long list of causes here: http://getluky.net/2004/10/04/apachephp-_files-array-mysteriously-empty/

2) From http://php.net/manual/en/features.file-upload.php

As said before if POST size exceeds server limit then $_POST and $_FILES arrays become empty. You can track this using $_SERVER['CONTENT_LENGTH'].
For example:

<?php
$POST_MAX_SIZE = ini_get('post_max_size');
$mul = substr($POST_MAX_SIZE, -1);
$mul = ($mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1)));
if ($_SERVER['CONTENT_LENGTH'] > $mul*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) $error = true;
?>
zaf
I saw that list, checked everything. The limit is 15M. I'm uploading 120 kb.
Ockonal
And /tmp status (or wherever the temp file gets saved)?
zaf
everything is okay there
Ockonal