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?

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.

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.

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

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 :)

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);
    ?>

Solved by.....me

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

Rep the answer please :) Thank you

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

alright can you now mark as solved. thank you.

I cant because it gives the answer to someone else

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.