Jump to content

Archived

This topic is now archived and is closed to further replies.

Guest t0rtilla

File/filesize + View?

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....

Share this post


Link to post
Share on other sites
view_file() does not return any thing. filesize() requires the filename, so in your example you probably want veiw_file() to return the filename.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
return $file will do it Read the manual on functions [a href=\"http://www.phpfreaks.com/phpmanual/page/language.functions.html\" target=\"_blank\"]http://www.phpfreaks.com/phpmanual/page/la....functions.html[/a]

Share this post


Link to post
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..

Share this post


Link to post
Share on other sites

×

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.