Simple file shredder in PHP

File shredding is used to destroy the data written on the disk. Usually rewrite the data once is enough to destroy the data, but for extreme measure, use super strong magnetic field.
The function I wrote below WORKS ONLY IF new data is written directly on top of the original file. This will be determined by your file system, and I don't know which file system works, but I know that NFS or Journaling file systems does not work.

function shred($filename,$strength=1,$fast=null){
	$size = filesize($filename);
 
	while($i < $strength){
		$fh = fopen($filename,'w');
		if($fast){
		$str = chr(rand(0,255));
			$str = str_repeat($str,$size);
		}else{
			$str = md5(rand(0,2147483647));
			$n = 32;
			while($n<$size){
				$str .= md5($str);
				$n+=32;
			}
		}
 
		fwrite($fh,substr($str,0,$size));
		fclose($fh);
		++$i;
	}
	return true;
}


Post new comment

The content of this field is kept private and will not be shown publicly.
If you have a Gravatar account, used to display your avatar.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <fn>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.

More information about formatting options

What is 49 + 28?
To combat spam, please solve the math question above.
Honey Pot that kill bots