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
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
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
Share on other sites

What im trying to do is basicly break up each line of output into Size and Name. It includes folders. So if the output is

 

120k Foldername123mFoldername I need it in byes btw,

$size = 120

$foldername = foldername

And repeate for each line of ouptput..

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.