Solved

php and filesize

Posted on 2013-01-02
8
236 Views
Last Modified: 2013-01-02
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
0
Comment
Question by:doctorbill
  • 5
  • 3
8 Comments
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 38737063
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

0
 

Author Comment

by:doctorbill
ID: 38737094
Doesn't work - all I get is the echo of the script on the page
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 38737134
Can you show us a full screenshot?
0
 

Author Comment

by:doctorbill
ID: 38737170
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.";
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 34

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 38737207
Oh, sorry - you should enclose lines 6, 7, and 8 with <?php (lines 6-8) ?>
0
 

Author Comment

by:doctorbill
ID: 38737246
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
0
 

Author Comment

by:doctorbill
ID: 38737256
Correction - it is working. I didn't have the correct (full) image  path in the database
0
 

Author Closing Comment

by:doctorbill
ID: 38737302
solved
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

29 Experts available now in Live!

Get 1:1 Help Now