Forum Moderators: coopster

Message Too Old, No Replies

unlink(); permission denied

permission denied when using unlink()

         

yt404

1:33 pm on May 2, 2004 (gmt 0)

10+ Year Member



I have used the unlunk function to delete a file once it gets too big, the code is below:

<?php
$error = "http://www.example.com/PHP/error.php"; // location of error page
$filename = "data.txt";
$box = "http://www.example.com/PHP/shout.php"; // URL of shout box
$max = 512; // maximum size (bytes) of data.txt file
if(filesize($filename) > $max) {
unlink($filename);
}

if (empty($name) ¦¦ empty($message)) { header( "Location: $error" );
} else {
print "Your shout has been added to the box, <a href=$box>Click here</a> to go back the the box ";
$a = fopen( $filename, "a") or die ("could not open $filename for writing please check file permissions");
flock($a, LOCK_SH);
fwrite($a, "<font face=verdana size=2><b>$name</b> : $message</font>
<hr noshade size=1>");
flock($a, LOCK_UN);
fclose($a);
}
?>

i get a permission denied error and the contents of the form ae still written to the file, can anyone see the problem?

[edited by: jatar_k at 5:28 pm (utc) on May 2, 2004]
[edit reason] generalized urls [/edit]

bird

2:56 pm on May 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



unlinking (deleting) a file doesn't change the file itself, it changes the directory where the file is located.
In other words, you need write permission on the directory.

yt404

4:40 pm on May 2, 2004 (gmt 0)

10+ Year Member



well there we go, thnaks very much m8 it works spot on now, cheers