Can't write over files

103 views Asked by At

I am trying to code a file shredder in PHP, and I get these errors:

Warning: fopen(calculate): failed to open stream: Permission denied in C:\XAMPP\htdocs\shred.php on line 9
Warning: fwrite() expects parameter 1 to be resource, string given in C:\XAMPP\htdocs\shred.php on line 11

<?PHP
$files = glob("*");

foreach ($files as $files) {
    $size = filesize($files);
    $bytes = "1";
    $writes = "1";
    while ($writes <= "3") {
    $data = fopen($files, "w");
        while ($bytes <= $size) {
            fwrite($files, "0");
            $bytes = $bytes + 1;
        }
    fclose($data);
    $writes = $writes + 1;  
    }
    //  unlink($files);
}
?>

I have no idea what to do at this point. The files aren't read only.

2

There are 2 answers

3
Yiğitcan Uçum On

You should use $data as the first parameter of fwrite.

0
Cedric Mariano On

Make sure you have the appropriate permissions because that is the common problem in using

fopen()

you can see the the same errors with this one.