Username: Save?
Password:
Home Forum Links Search Login Register*
    News: Keep The TechnoWorldInc.com Community Clean: Read Guidelines Here.
Recent Updates
[May 17, 2024, 05:02:16 PM]

[May 17, 2024, 05:02:16 PM]

[May 17, 2024, 05:02:16 PM]

[May 17, 2024, 05:02:16 PM]

[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[March 06, 2024, 02:45:27 PM]
Subscriptions
Get Latest Tech Updates For Free!
Resources
   Travelikers
   Funistan
   PrettyGalz
   Techlap
   FreeThemes
   Videsta
   Glamistan
   BachatMela
   GlamGalz
   Techzug
   Vidsage
   Funzug
   WorldHostInc
   Funfani
   FilmyMama
   Uploaded.Tech
   MegaPixelShop
   Netens
   Funotic
   FreeJobsInc
   FilesPark
Participate in the fastest growing Technical Encyclopedia! This website is 100% Free. Please register or login using the login box above if you have already registered. You will need to be logged in to reply, make new topics and to access all the areas. Registration is free! Click Here To Register.
+ Techno World Inc - The Best Technical Encyclopedia Online! » Forum » THE TECHNO CLUB [ TECHNOWORLDINC.COM ] » Programming Zone » PHP
 Find size of a file or image in PHP
Pages: [1]   Go Down
  Print  
Author Topic: Find size of a file or image in PHP  (Read 1011 times)
Hellraiser
TWI Trailblazer
*******



Karma: 3
Offline Offline

Posts: 2476


View Profile
Find size of a file or image in PHP
« Posted: August 29, 2007, 10:32:24 AM »


Find size of a file or image in PHP

You can find the filesize using an inbuild PHP function filesize(). And display the filesize in human readable format use again PHP function number_format

Example

Assume that all the files are stored in a folder called download

Code:
$my_file=download/abc.doc;

$file_size = filesize($my_file);

if ($file_size >= 1073741824) { $show_filesize = number_format(($file_size / 1073741824),2) . " GB"; }
elseif ($file_size >= 1048576) { $show_filesize = number_format(($file_size / 1048576),2) . " MB"; }
elseif ($file_size >= 1024) { $show_filesize = number_format(($file_size / 1024),2) . " KB"; }
elseif ($file_size >= 0) { $show_filesize = $file_size . " bytes"; }
else { $show_filesize = "0 bytes"; }
echo $show_filesize;

abc.doc is the filename but where did we get it? answer from the database. How? like this->

Assume the database has already been connected. Now open the table retrieve the file name. Assume again a table called file exists with what ever fields.

Code:
$res=mysql_query("select * from file");
$row=mysql_fetch_array($res);
$my_file=$row["filename"];

Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Copyright © 2006-2023 TechnoWorldInc.com. All Rights Reserved. Privacy Policy | Disclaimer
Page created in 0.108 seconds with 24 queries.