Jump to content


File/filesize + View?


  • Please log in to reply
4 replies to this topic

#1 Guest_t0rtilla_*

Guest_t0rtilla_*
  • Guests

Posted 27 June 2006 - 11:07 PM

// 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];
        }

how can i make it work?

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

thn it doesnt work....

#2 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 28 June 2006 - 12:02 AM

view_file() does not return any thing. filesize() requires the filename, so in your example you probably want veiw_file() to return the filename.

Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#3 Guest_t0rtilla_*

Guest_t0rtilla_*
  • Guests

Posted 28 June 2006 - 12:45 AM

// file view $file
function view_file()
         {
                 $open = opendir('.');
                 while ($file = readdir($open))
                 {
                         echo $file;
                 }
         }

how can i use $file out of file_view() function?

#4 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 28 June 2006 - 12:56 AM

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]
Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#5 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 28 June 2006 - 02:20 AM

Try "returning" the value...

from (http://www.w3schools...p_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]
<html>
<body><?php
function add($number1,$number2)
  {
  $total = $number1 + $number2;
  return $total;
  }$added_number = add(1,16);echo "1 + 16 = ".$added_number;
?></body>
</html>

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

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users