$_FILES size problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
captcadaver
Forum Newbie
Posts: 17
Joined: Fri Jul 17, 2009 11:12 pm

$_FILES size problems

Post by captcadaver »

Hi, I'm trying to figure out why I can't see what size this file is. I use file size to determine if there's a picture in a slot.

Here's my relevant code:

Code: Select all

<?php include 'config.inc.php'; ?>
<html><head><title>Submit Pictures</title></head>
<body> 
<?php
// script stolen from event pic uploader
$details .= "> Processing Images...<br/>";
 
// get info
$aid = $_POST['aid'];
$date = time();
 
// get gid associated w/ aid
$sql_gid = "SELECT * FROM photo_album WHERE aid='$aid'";
$result_gid = mysql_query($sql_gid) or die(mysql_error());
$array_gid = mysql_fetch_array($result_gid) or die(mysql_error());
$gid = $array_gid[gid];
 
// DEBUG
echo print_r($_FILES);
 
// for every picture slot...
for($i=1; $i<=5; $i++)
    {
    // check if there was a file uploaded in that picture slot
    if ($_FILES['pic']['size']['$i'] > 0)
        {
            echo "<br/> file $i is in pic slot  <br/>";
                }
 
    else //this else{} is just here for debug
        {
        $size_fail = $_FILES['pic']['size']['$i'];
        print "<br/> line 61 failure. size = $size_fail <br/>";
        }
    } // } for loop
?>
Output when I tried to upload the same two images:

Code: Select all

Array ( [pic] => Array ( [name] => Array ( [1] => lolcat-funny-picture-moderator1.jpg [2] => lolcat-funny-picture-moderator1.jpg [3] => [4] => [5] => ) [type] => Array ( [1] => image/jpeg [2] => image/jpeg [3] => [4] => [5] => ) [tmp_name] => Array ( [1] => /var/tmp/phpbwL1Os [2] => /var/tmp/phph9HGtq [3] => [4] => [5] => ) [error] => Array ( [1] => 0 [2] => 0 [3] => 4 [4] => 4 [5] => 4 ) [size] => Array ( [1] => 41096 [2] => 41096 [3] => 0 [4] => 0 [5] => 0 ) ) ) 1
line 61 failure. size =
 
line 61 failure. size =
 
line 61 failure. size =
 
line 61 failure. size =
 
line 61 failure. size =
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: $_FILES size problems

Post by VladSun »

Try not using string as array index but integer:

Code: Select all

$_FILES['pic']['size']['$i']
=>

Code: Select all

$_FILES['pic']['size'][$i]
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply