Forum Moderators: coopster

Message Too Old, No Replies

unlink error, pls help.

images refuse to delte with unlink function, need a way out

         

dewteks

10:07 am on Oct 7, 2008 (gmt 0)

10+ Year Member




Hello All,
I have being trying to create a script to delete images from a directory (../models/) but each time i try to delete any of the images displayed, it shows this error msg:

Warning: unlink() [function.unlink]: No such file or directory in /home/uniquepr/public_html/admin/modellist.php on line 59

<?
if (isset($_GET['deletefile'])) {
if(unlink($deletefile)) echo "File Deleted ";//line 59}echo"<ol>";$handle=opendir("../models/");while (($file = readdir($handle))!==false) {echo('<li>' .$file. '<a href="' . $_SERVER['PHP_SELF'] . '?deletefile=' . $file . '"> ' . ' ¦ Delete File </a></li></BR>');}closedir($handle);echo"</ol>";
?>

I have tried all sorts of arrangement for the unlink function and non seems to work. any help will be appreciated please.

andrewsmd

12:11 pm on Oct 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I work with these functions a lot. It sounds like you have a directory problem. Where exactly are the files located on your machine or network. A good way to tell if the directory your are passing in exists is to put it into a glob function. Basically do a var_dump(glob($_GET['deletefile'])); and see what you get. If that gives you an array of nothing then your path entered in is incorrect. Try playing around with the path you enter in if that is the case.

dreamcatcher

2:27 pm on Oct 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you sure:

unlink($deletefile)

shouldn`t be:

unlink($_GET['deletefile'])

dc

nilsk123

12:39 pm on Oct 8, 2008 (gmt 0)

10+ Year Member



unlinking whatever the user puts in doesn't sound like the way to go, watch it.