Solved

php and filesize

Posted on 2013-01-02
8
235 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
Comment Utility
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
Comment Utility
Doesn't work - all I get is the echo of the script on the page
0
 
LVL 34

Expert Comment

by:gr8gonzo
Comment Utility
Can you show us a full screenshot?
0
 

Author Comment

by:doctorbill
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 34

Accepted Solution

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

Author Comment

by:doctorbill
Comment Utility
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
Comment Utility
Correction - it is working. I didn't have the correct (full) image  path in the database
0
 

Author Closing Comment

by:doctorbill
Comment Utility
solved
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

762 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

11 Experts available now in Live!

Get 1:1 Help Now