1,105,423 Community Members

Cannot delete file from server using PHP

Member Avatar
riahc3
 
1,404 posts since May 2008
Reputation Points: 45 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 18 [?]
Team Colleague
 
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?

Member Avatar
hakeemtunde
Junior Poster in Training
54 posts since Dec 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 3 [?]
 
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.

Member Avatar
riahc3
 
1,404 posts since May 2008
Reputation Points: 45 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 18 [?]
Team Colleague
 
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.

Member Avatar
hakeemtunde
Junior Poster in Training
54 posts since Dec 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 3 [?]
 
0
 

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

Member Avatar
riahc3
 
1,404 posts since May 2008
Reputation Points: 45 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 18 [?]
Team Colleague
 
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 :)

Member Avatar
riahc3
 
1,404 posts since May 2008
Reputation Points: 45 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 18 [?]
Team Colleague
 
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);
    ?>
Member Avatar
riahc3
 
1,404 posts since May 2008
Reputation Points: 45 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 18 [?]
Team Colleague
 
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");
?>
Member Avatar
riahc3
 
1,404 posts since May 2008
Reputation Points: 45 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 18 [?]
Team Colleague
 
0
 

Rep the answer please :) Thank you

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

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

Member Avatar
hakeemtunde
Junior Poster in Training
54 posts since Dec 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 3 [?]
 
0
 

alright can you now mark as solved. thank you.

Member Avatar
riahc3
 
1,404 posts since May 2008
Reputation Points: 45 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 18 [?]
Team Colleague
 
0
 

I cant because it gives the answer to someone else

Member Avatar
Ezzaral
Posting Sage
7,431 posts since May 2007
Reputation Points: 2,714 [?]
Q&As Helped to Solve: 953 [?]
Skill Endorsements: 31 [?]
Moderator
Featured
 
2
 

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

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