homepage Welcome to WebmasterWorld Guest from 54.242.18.232
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Foreach, multiple file uploads and an if statement
Sub_Seven




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

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.

 

Readie




msg:4389122
 7:49 pm on Nov 20, 2011 (gmt 0)

$_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);

Sub_Seven




msg:4389721
 6:19 am on Nov 22, 2011 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved