TechMistress Posted January 9, 2010 Share Posted January 9, 2010 Hello - I have an array of images I'm displaying from a folder. All works great, until I try to get the filesize. It displays the filesize fine if there is only ONE image in the array, but as soon as I have more than on, I get an error like this: Warning: filesize() [function.filesize]: stat failed for 262995292_offer_christmasstory.jpg|1262980260_offer_TEST.jpg in (they run together) Here is the code I am using: $images = "<table width=270 cellspacing=0 cellpadding=0 align=left><tr>"; if(!empty($ap[image])) { $MyImages = explode("|", $ap[image]); while(list(,$vi) = each($MyImages)) { $myfile .= "re_images/$vi"; $size = filesize($myfile); if( $size > 153600 ) { $filesize = round( $size/1024, 2 ) . ' KB<br><font color=#FF0000><strong>ERROR: This file is too large<br>Click Below to delete it.</font></strong>'; } else { $filesize = round( $size/1024, 2 ) . ' KB'; } $images .= "<td align=center style=\"padding-bottom:15\"><img src=\"re_images/$vi\" width=50 height=50><br>$filesize<br> <a class=RedLink href=\"delete_image.php?id=$ap[ListingID]&file=$vi\">delete</a></td>"; $mi++; } } $images .= "</tr>\n"; Link to comment https://forums.phpfreaks.com/topic/187780-help-i-cant-find-the-small-solution/ Share on other sites More sharing options...
cags Posted January 9, 2010 Share Posted January 9, 2010 That's an odd choice for iterating through the array. Why not just use something like... foreach($MyImages as $file) { Looking at your code this $myfile .= "re_images/$vi"; is likely your problem. On each iteration of the loop you are concatenating the values together. Lets say your folder contains image1.jpg, image2.jpg, image3.jpg. In theory the first loop should work, but on the second $myfile will consist of 're_images/image1.jpgre_images/image2.jpg'. Personally I'd just go for something along the lines of... if(!empty($ap['image'])){ $MyImages = explode("|", $ap['image']); foreach($MyImages as $myfile) { $size = filesize('re_images/'.$myfile); Link to comment https://forums.phpfreaks.com/topic/187780-help-i-cant-find-the-small-solution/#findComment-991428 Share on other sites More sharing options...
TechMistress Posted January 9, 2010 Author Share Posted January 9, 2010 Ok, let me preface this by saying I've never really coded before. I'm trying to add something to my old programmer's code (mistake #1). So, I did the following and it worked great! Thank you so very much! I'm only doing this because I couldn't get the page to check the file size before uploading, but this works well. $MyImages = explode("|", $ap[image]); while(list(,$vi) = each($MyImages)) { $size = filesize('re_images/'.$vi); Link to comment https://forums.phpfreaks.com/topic/187780-help-i-cant-find-the-small-solution/#findComment-991439 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.