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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Warning Message

Status
Not open for further replies.

jayne1

Technical User
Feb 5, 2002
7
GB
Hi all (...just luv this site!)

I have a script which deletes selected files.....it works fine except everytime i delete something it comes up with this warning message on the web browser:-

Warning: Unlink failed (Is a directory) in httpd/html/form_del.php on line 7

Anyone have an idea as to how to get rid of this message? here is the code i am using:

$delrec2=count($delfile);
for ($a=0;$a<=$delrec2;$a++){
$matchdate = $delfile[$a];
unlink(&quot;results/$matchdate&quot;);
}

 
You might find that $matchdate is empty at some point, this would mean that unlink tried to do:
[tt]
unlink(&quot;results/&quot;);
[/tt]
which won't work. Try printing out the value of matchdate before you try and unlink the file to see if it is in fact empty, if it is this could indicate an error elsewhere in your script.

Will.
fortytwo
will@hellacool.co.uk
 
it fails cause you cannot delete the file.

one simple way to get rid of the message is to put an '@' before, like this @ulink(...)

This way PHP doesnot write any error, you must control errors by the return value of the function Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
$delrec2=count($delfile);
for ($a=0;$a<=$delrec2;$a++){
$matchdate = $delfile[$a];
unlink(&quot;results/$matchdate&quot;);
}

Thinking like the computer...

$delrec2 is the number of records to delete...
The for loop sets $a to 0 (since you're using it as an array index), but increments $a UNLESS $a is GREATER THAN $delrec2
Your array index starts at 0, while the count starts at 1, so when $a == $delrec2 (last iteration of the loop), you're actually already past the end of the array, leaving you with an empty $matchdate as fortytwo said.

Change the $a<=$delrec2 to just $a<$delrec2 and I think it should avoid giving you any errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top