Forum Moderators: coopster

Message Too Old, No Replies

file delete help

         

adammc

1:02 am on Jun 29, 2006 (gmt 0)

10+ Year Member



Hi Guys,

Im having trouble getting this unlink code to work :(
Can anyone please help?

[php]
// Delete the pictures associated with the product

$file = "$picture";

if (!file_exists("../../../product-images/$file")) {
print "Error: cant find the picture";
exit;
}

//if we've gotten to this point, we know the file does exist

if (!unlink($file)) // attempt to delete the file
{
echo ("Error deleting $file");
exit;

}else{

echo ("The image has been deleted");

} // End of file delete process
[/php]

Its getting to this line:
[php]
if (!unlink($file))
[/php]

And telling me:
Error deleting 11515425661.jpg

adammc

1:12 am on Jun 29, 2006 (gmt 0)

10+ Year Member



Nevermind :)

Found the prob, it wanted the full path here:

[php]
if (!unlink("../../../product-images/$file")) // attempt to delete the file
[/php]

eelixduppy

6:15 am on Jun 29, 2006 (gmt 0)



I'm glad you got it. You have to remember it's looking for the file relative to the current directory the script is in ;)