Jump to content

File/filesize + View?


Guest t0rtilla

Recommended Posts

Guest t0rtilla
[code]
// file view $file
function view_file()
         {
                 $open = opendir('.');
                 while ($file = readdir($open))
                 {
                         echo $file;
                 }
         }
// file size
function size_hum_read($size)
        {
                $i=0;
                $iec = array(" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
                while(($size/1024)>1)
        {
                $size=$size/1024;
                $i++;
        }
                return substr($size,0,strpos($size,'.')+4).$iec[$i];
        }
[/code]

how can i make it work?

if i echo size_hum_read(filesize(view_file()));

thn it doesnt work....
Link to comment
Share on other sites

Guest t0rtilla
[code]// file view $file
function view_file()
         {
                 $open = opendir('.');
                 while ($file = readdir($open))
                 {
                         echo $file;
                 }
         }[/code]

how can i use $file out of file_view() function?
Link to comment
Share on other sites

Try "returning" the value...

from (http://www.w3schools.com/php/php_functions.asp)
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]PHP Function Return value
Functions can not only write information to the output, they can also return values.

Example[/quote]
[code]
<html>
<body><?php
function add($number1,$number2)
  {
  $total = $number1 + $number2;
  return $total;
  }$added_number = add(1,16);echo "1 + 16 = ".$added_number;
?></body>
</html> [/code]

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]The output of the code above will be:

1 + 16 = 17 [/quote]

Also, might look at this script - comes close to what it looks you are trying to do.

[a href=\"http://www.nstoia.com/toh/technical/listdir/\" target=\"_blank\"]http://www.nstoia.com/toh/technical/listdir/[/a]

Lite..
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.