Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unlink not deleting file

Status
Not open for further replies.

andy98

Programmer
Jul 7, 2000
120
GB
Hi

I am trying to remove an image file from a webserver and have got 777 permissions on the directory but cannot remove the file.

I know the action part is working and it is entering the IF statement! And I know that the $filename returned can be accessed when I paste it into a web browser.

Is my code incorrect?

Code:
$filename = "[URL unfurl="true"]http://www.mywebsite/images/$_GET[/URL][fullpic]";

if ($action == 'delImage')
{

echo "$filename<br><bR>";

		if(file_exists($filename))
		{
		echo "File does exist really";
		unlink($filename);
		}

		else
		{
		echo "the file does not exist";
		} 
}

And even when I place my UNLINK somewhere in the IF statement where is does get processed all I get back is:
Code:
Warning: Unlink failed (No such file or directory)



 
Sometimes the URL wrappers provided with PHP come back to bite you. It seems to cloud peoples' understanding about the differences between files conveniently retrieved via HTTP requests and directly read from the file system.
It would be absolutely horrible if files could be deleted via HTTP requests.
 
you can, this is from the HTTP rfc.

9.7 DELETE
The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the operation has been carried out, even if the status code returned from the origin server indicates that the action has been completed successfully. However, the server SHOULD NOT indicate success unless, at the time the response is given, it intends to delete the resource or move it to an inaccessible location.

A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity.

If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.
 
Seems like you overdoing it. More is not always better.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top