Jump to content

Help, I can't find the small solution!


TechMistress

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.