Link to home
Start Free TrialLog in
Avatar of doctorbill
doctorbillFlag for United Kingdom of Great Britain and Northern Ireland

asked on

php and filesize

On the attached page, the following scripts wotk fine with a static image:
--------------------------
<?php
echo filesize("downloads/picture3hr.jpg");
echo "&nbsp;&nbsp;File Size in Bytes";
?><br />

<?php

$f = "downloads/picture3hr.jpg";
$size = filesize($f) * .000001;
echo $f . " is " . $size . " Mega bytes.";
?>
----------------------
The above scripts were used just to test the page
I am trying to get the file size from the following code being fed from a mysql recordset:
------------------
  <?php do {
            
        ?>
        <img src="<?php echo $row_imgs[im_thumb]; ?>" border="0" /><a href="download.php?file=<?php echo $row_imgs[im_hres]; ?>">D</a>
        <?php } while ($row_imgs = mysql_fetch_assoc($imgs)); ?>
-------------------
Can someone please point me in the direction of how to add the filesize function to this loop so that it returns to file size for all returned records
index.php
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

This might work, depending on where the images actually are, but you didn't say anything about where you want the filesize to show up, so the code below will simply put it to the side:

<?php do { 
            
        ?>
        <img src="<?php echo $row_imgs["im_thumb"]; ?>" border="0" /><a href="download.php?file=<?php echo $row_imgs["im_hres"]; ?>">D</a>

$f = $row_imgs["im_thumb"];
$size = filesize($f) * .000001;
echo $f . " is " . $size . " Mega bytes.";

        <?php } while ($row_imgs = mysql_fetch_assoc($imgs)); ?>

Open in new window

Avatar of doctorbill

ASKER

Doesn't work - all I get is the echo of the script on the page
Can you show us a full screenshot?
The following is repeated down the page next to each image:
----------------------
$f = $row_imgs["im_thumb"]; $size = filesize($f) * .000001; echo $f . " is " . $size . " Mega bytes.";
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I get the following next to the relevant image:

FW_001.jpg is 0 Mega
FW_002.jpg is 0 Mega
FW_003.jpg is 0 Mega

So it is working in terms of the script on the page but no size is being returned
Correction - it is working. I didn't have the correct (full) image  path in the database
solved