We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,001 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Cannot delete file from server using PHP

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
1 Day
Discussion Span
5 Months Ago
Last Updated
12
Views
riahc3
 
Team Colleague
1,300 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11

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.

hakeemtunde
Junior Poster in Training
50 posts since Dec 2007
Reputation Points: 10
Solved Threads: 8
Skill Endorsements: 2

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.

riahc3
 
Team Colleague
1,300 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11

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

hakeemtunde
Junior Poster in Training
50 posts since Dec 2007
Reputation Points: 10
Solved Threads: 8
Skill Endorsements: 2

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

riahc3
 
Team Colleague
1,300 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11

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);
    ?>
riahc3
 
Team Colleague
1,300 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11

Solved by.....me

<?php
$fp = fopen(getcwd()."/test.txt", "w");
fwrite($fp, "hello");
fclose($fp);
chmod(getcwd()."/test.txt", 0777);
unlink(getcwd()."/test.txt");
?>
riahc3
 
Team Colleague
1,300 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11

Rep the answer please :) Thank you

riahc3
 
Team Colleague
1,300 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11

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

AndreRet
Industrious Poster
4,706 posts since Jan 2008
Reputation Points: 391
Solved Threads: 481
Skill Endorsements: 20

alright can you now mark as solved. thank you.

hakeemtunde
Junior Poster in Training
50 posts since Dec 2007
Reputation Points: 10
Solved Threads: 8
Skill Endorsements: 2

I cant because it gives the answer to someone else

riahc3
 
Team Colleague
1,300 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11

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

Ezzaral
null
Moderator
16,111 posts since May 2007
Reputation Points: 3,292
Solved Threads: 873
Skill Endorsements: 28

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1376 seconds using 2.67MB