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?

4
Contributors
11
Replies
13
Views
4 Years
Discussion Span
Last Post by Ezzaral
Featured Replies
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.

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");
?>
Votes + Comments
Nice :)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.