Jump to content

PHP Exec


clanstyles

Recommended Posts

Hey, im trying to isolate the file size from the file/folder names.

I  have come up with this but it doesn't work right and well.

 

exec("du -s *", $output);
for($i=0; $i < sizeof($output); $i++)
{
	echo $output[$i];
	if($output[$i] == "\t")
	{
		echo "====>" . $output[$s] . "<br />";
	}
	//echo $output[$i] . "<br />";
}

 

Could somebody please help.

 

Thank You in advance.

Link to comment
https://forums.phpfreaks.com/topic/57464-php-exec/
Share on other sites

I found a self-made function on php.net:

 medhefgo at googlemail dot com
02-Jun-2007 03:02
I created another dirsize() function which doesn't use recursion.
I gained a ~2-3% performance boost while it uses ~50% lesser memory!

<?php
function dirsize($dirname) {
    if (!is_dir($dirname) || !is_readable($dirname)) {
        return false;
    }

    $dirname_stack[] = $dirname;
    $size = 0;

    do {
        $dirname = array_shift($dirname_stack);
        $handle = opendir($dirname);
        while (false !== ($file = readdir($handle))) {
            if ($file != '.' && $file != '..' && is_readable($dirname . DIRECTORY_SEPARATOR . $file)) {
                if (is_dir($dirname . DIRECTORY_SEPARATOR . $file)) {
                    $dirname_stack[] = $dirname . DIRECTORY_SEPARATOR . $file;
                }
                $size += filesize($dirname . DIRECTORY_SEPARATOR . $file);
            }
        }
        closedir($handle);
    } while (count($dirname_stack) > 0);

    return $size;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/57464-php-exec/#findComment-284314
Share on other sites

Thats not what I need. I can get the fiel size fine with exec. I need to do it this way because im connecting with ssh2_connect to many servers I have this done already works fine.

 

I get a print out with that exec like:

 

112 BMMods.rar8 Brent.txt12 BrentAIM.txt4 Gungame.rar4 Jumba.rar4 ReadMe.txt12 blackmarket12 carmod.rar4 config.php4 footer.php116 gungame.sql60460 half-life 2 deathmatch.rar4 header.php8 hl.class.php4 index.php284 java1300 layout.bmp49560 music652 raiderboy4 search.php4 ssh.php28 technicolor52 test4 whatismyip4 work.txt

 

I need to get the filesize and the directory name seperate so I can hold them for each instance of that. So tahts why i was going to look for a space. I don't know the best way to do this though/

Link to comment
https://forums.phpfreaks.com/topic/57464-php-exec/#findComment-284325
Share on other sites

Archived

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

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