Welcome to WebmasterWorld Guest from 54.166.191.159

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Foreach, multiple file uploads and an if statement

     
8:05 am on Nov 20, 2011 (gmt 0)

5+ Year Member



Hi all,

I am having a problem that has me going crazy, it's been too much trial and error and I just need another set of eyes

This is my code:


$testname= 'testnewname';
$picsI= 0;
$testpreimgtype= '.jpg';
foreach($_FILES["pictures"]["error"] as $key => $error){
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
if($error == 0 && $_FILES["pictures"]["size"] < 10000){
$name = $_FILES["pictures"]["name"][$key];
move_uploaded_file($tmp_name, "$imgDir" . $_FILES["pictures"]["name"]);
rename("$imgDir".$_FILES["pictures"]["name"], "$imgDir".$testname ."-".$picsI.$testpreimgtype);
echo 'success';
$picsI++;
}
else{
echo $error;
}
}


What is going on here is that this part specifically breaks the code: "if($error == 0 && $_FILES["pictures"]["size"] < 10000)", now if I just remove the size verification like this: "if($error == 0)" it works; its just something i'm missing in the other part of the if statement where I'm trying to check for the image size...

Would anyone happen to know why this happens? Thanks everyone.
7:49 pm on Nov 20, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



$_FILES["pictures"]["size"] < 10000

This needs to be
$_FILES["pictures"]["size"][$key] < 10000

:)

And the same treatment needs to be given in these too:
move_uploaded_file($tmp_name, "$imgDir" . $_FILES["pictures"]["name"]);
rename("$imgDir".$_FILES["pictures"]["name"], "$imgDir".$testname ."-".$picsI.$testpreimgtype);
6:19 am on Nov 22, 2011 (gmt 0)

5+ Year Member



Hey Readie, when you're right you're right, it works with no problem, thanks a lot for the help :)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month