1.11M Members

Cannot delete file from server using PHP

 
0
 

Hello

First off the server is running Windows 7 32bits.

I have the following code:

<?php
$fp = fopen(getcwd()."/test.txt", "w");
fwrite($fp, "hello");
chmod(getcwd()."/test.txt", 0777);
unlink(getcwd()."/test.txt");
fclose($fp);
?>

It creates the file perfectly but afterwards I cannot delete it. Giving me this error:

Warning: unlink(C:\test.txt) [function.unlink]: Permission denied in C:\writeanddel.php on line 4

First off, I know chmod doesnt work in Windows but I added it anyways.

Second, Im sure that the folder test is written on (obviously not C:/) has complete write/read access for everyone.

Whats wrong and how can I do this correctly?

 
0
 

my little advise for you is create a folder and set the access permission through windows for that folder to be read/writable then further with your program.

 
0
 

my little advise for you is create a folder and set the access permission through windows for that folder to be read/writable then further with your program.

I already set the permissions for that folder. Still does not work.

 
0
 

ok try copy a file to it and check it permission if is read/write then from your php scrip delete it.

 
0
 

ok try copy a file to it and check it permission if is read/write then from your php scrip delete it.

What? Please speaker clearer :)

 
0
 

I made a copy of the file that I originally write and I can delete that copy:

    <?php
    $fp = fopen(getcwd()."/test.txt", "w");
    fwrite($fp, "hello");
    chmod(getcwd()."/test.txt", 0777);
    copy(getcwd()."/text.txt", getcwd()."/something.txt");
    unlink(getcwd()."/something.txt"); /*THIS WORKS*/
    unlink(getcwd()."/test.txt"); /*THIS DOES NOT WORK*/
    fclose($fp);
    ?>
 
0
 

Solved by.....me

<?php
$fp = fopen(getcwd()."/test.txt", "w");
fwrite($fp, "hello");
fclose($fp);
chmod(getcwd()."/test.txt", 0777);
unlink(getcwd()."/test.txt");
?>
 
0
 

Rep the answer please :) Thank you

 
0
 

Rep'ed. Now mark as solved please :) Thank You

 
0
 

alright can you now mark as solved. thank you.

 
0
 

I cant because it gives the answer to someone else

 
2
 

Well, I can. Solved is solved and you stated it to be so.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article