Jump to content

Folder Size


Cod-nes

Recommended Posts

Am I doing something wrong?

if (dir($_COOKIE['Username']) >= size(40000000)){echo "Sorry but you already used up your space";} else{?><form action="upload_file.php" method="post"enctype="multipart/form-data"><label for="file">Filename:</label><input type="file" name="file" id="file"> <br><input type="submit" name="submit" value="Submit"></form><br>Max File limit: 10MB<br>10MB = 10 000 KB = 10 000 000 B<?php}?>

Link to comment
Share on other sites

size() is not a function and dir() returns a directory handler Object. You'll have to loop through the files in that directory and filesize() each one, then add up them.

Link to comment
Share on other sites

So like this?

$user = $_COOKIE;$limit = 0;while ($file = (readdir(opendir($user))) !== false){echo "$file . $filesize($file)";$limit+(filesize($file));}if ($limit >= 40000000){die(Sorry but you reached your limit of space);}else{?><form action="upload_file.php" method="post"enctype="multipart/form-data"><label for="file">Filename:</label><input type="file" name="file" id="file"> <br><input type="submit" name="submit" value="Submit"></form><br>Max File limit: 10MB<br>10MB = 10 000 KB = 10 000 000 B<?php}?>

Link to comment
Share on other sites

Err... try this function, I found it in the manual

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

Archived

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

×
×
  • Create New...