?
Solved

php and filesize

Posted on 2013-01-02
8
Medium Priority
?
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 35

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 35

Expert Comment

by:gr8gonzo
ID: 38737134
Can you show us a full screenshot?
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

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
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 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