hi,

in a php-script someone else wrote I found
'<input type="file" name="photo[]" accept="image/jpeg">':

echo "    <tr>\n";
echo "      <td width=\"130\" height=\"30\"></td>\n";
echo "      <td width=\"370\" height=\"30\"><input type=\"file\" name=\"photo[]\" 
accept=\"image/jpeg\"></td>\n";
echo "    </tr>\n";
echo "    <tr>\n";
echo "      <td width=\"130\" height=\"30\"></td>\n";
echo "      <td width=\"370\" height=\"30\"><input type=\"file\" name=\"photo[]\" 
accept=\"image/jpeg\"></td>\n";
echo "    </tr>\n";
echo "    <tr>\n";
echo "      <td width=\"130\" height=\"30\"></td>\n";
echo "      <td width=\"370\" height=\"30\"><input type=\"file\" name=\"photo[]\" 
accept=\"image/jpeg\"></td>\n";
echo "    </tr>\n";
echo "    <tr>\n";
echo "      <td width=\"130\" height=\"30\"></td>\n";
echo "      <td width=\"370\" height=\"30\"><input type=\"file\" name=\"photo[]\" 
accept=\"image/jpeg\"></td>\n";
echo "    </tr>\n";

and this is the code which is run by the form's action-attribute
(same script as above):

for( $i = 0; $i < count( $photo ); $i++ )
{
  if( $photo[ $i ] != "" && $photo[ $i ] != "none" )
  {
    if( $photo_size[ $i ] > 500000 ) error( "Ungültige Fotogröße" );
    if($photo_type[ $i ] == "image/pjpeg" || $photo_type[ $i ] == "image/jpeg")
      $newphoto[] = $photo[ $i ];
    else
      error( "Ungültiger Dateityp, bitte wählen Sie JPEG " );
  }
}

(you can find the complete file here:
 http://home.t-online.de/~fam.natter/list.php)

Now the problem is that the above code only works with php 4.0.6 and
not with php 4.0.0: php 4.0.0 puts the type and name and
temporary-file information in the $image array while 4.0.6 puts it in
$image_type and $image (both use $image_size). See the example output
below for more information.

Here is a small test-case:
============ test_files.html ===============
<html>
<head><title>Test</title></head>
<body>
<form action="test_files.php" method="post" enctype="multipart/form-data">
        <input type="file" name="image[]" accept="image/jpeg">
        <input type="file" name="image[]" accept="image/jpeg">
        <input type="submit" value="submit">
</form>
</body>
</html>
============================================
============ test_files.php ================
<?php

        if (!isset ($image))  {
                echo "<b>Missing Parameter in test_file.php!</b>";
                exit;   
        }
        if (isset ($image_type))
                echo "<b>image_type is set !</b><br>";
        if (isset ($image_size))
                echo "<b>image_size is set !</b><br>";
        for ($i = 0; $i < count ($image); $i++)
        {
                echo "<b>image[$i]='" . $image[$i] . "'<b>\n";
        }

?>
============================================

Here is the output with two different versions of php when I select
two jpeg images (northbeach.jpg and Water01.jpg):

This is the output with php 4.0.6:
image_type is set !
image_size is set !
image[0]='/tmp/phpvRpXFA' image[1]='/tmp/phpfvgzMk'

This is the output with php 4.0.0:
image_size is set !
image[0]='northbeach.jpg' image[1]='image/jpeg' image[2]='/tmp/phpZApBAO' 
image[3]='Water01.jpg' image[4]='image/jpeg' image[5]='/tmp/phpC3YeVs'


So how can I use this input-file array (image[] in the example)
portably ?


BTW: how can I get access to /tmp/phpZApBAO (I need to create
thumbnails from the images) ? On some servers this seems to create
permission-problems (but I cannot change the configuration of the
server).

-- 
Felix Natter

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to