Guest t0rtilla Posted June 27, 2006 Share Posted June 27, 2006 [code]// file view $filefunction view_file() { $open = opendir('.'); while ($file = readdir($open)) { echo $file; } }// file sizefunction 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 https://forums.phpfreaks.com/topic/13059-filefilesize-view/ Share on other sites More sharing options...
dptr1988 Posted June 28, 2006 Share Posted June 28, 2006 view_file() does not return any thing. filesize() requires the filename, so in your example you probably want veiw_file() to return the filename. Link to comment https://forums.phpfreaks.com/topic/13059-filefilesize-view/#findComment-50261 Share on other sites More sharing options...
Guest t0rtilla Posted June 28, 2006 Share Posted June 28, 2006 [code]// file view $filefunction view_file() { $open = opendir('.'); while ($file = readdir($open)) { echo $file; } }[/code]how can i use $file out of file_view() function? Link to comment https://forums.phpfreaks.com/topic/13059-filefilesize-view/#findComment-50270 Share on other sites More sharing options...
dptr1988 Posted June 28, 2006 Share Posted June 28, 2006 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] Link to comment https://forums.phpfreaks.com/topic/13059-filefilesize-view/#findComment-50271 Share on other sites More sharing options...
litebearer Posted June 28, 2006 Share Posted June 28, 2006 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 valueFunctions can not only write information to the output, they can also return values.Example[/quote][code]<html><body><?phpfunction 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 https://forums.phpfreaks.com/topic/13059-filefilesize-view/#findComment-50276 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.