[solved]Delete File message unwanted

Alles, was PHP betrifft, kann hier besprochen werden.

[solved]Delete File message unwanted

Postby mickeymouse » 19. March 2012 23:18

I want to allow my user to delete a file. He does this by entering the file name in a form and submits it.

My code for the delete is:
if (!unlink($file))
but if the delete doen't work, e.g., the file is not there, I get (in my test) the following message and I suppose my user will get the same message.

"Warning: unlink(dinapoli_anntest.jpg) [function.unlink]:
No such file or directory in C:\xampp\htdocs\Annuaire\AF_DeleteFile.php on line 40"

Is there something I can do to prevent getting this message. (I give my user my own message.)

Thank you / Danke!
mickeymouse
 
Posts: 36
Joined: 08. March 2009 06:10
Location: France & Canada
XAMPP Version: 5.6.3
Operating System: Win 7 Family Prem Ed (64 bit?)

Re: Delete File message unwanted

Postby Altrea » 19. March 2012 23:39

Hi mickeymouse,

you can check if the file exists before you try to delete a not present file: file_exists()

best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 6946
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: Windows 10 Pro x64

Re: Delete File message unwanted

Postby mickeymouse » 20. March 2012 00:48

Thank you. works fine now.
mickeymouse
 
Posts: 36
Joined: 08. March 2009 06:10
Location: France & Canada
XAMPP Version: 5.6.3
Operating System: Win 7 Family Prem Ed (64 bit?)


Return to PHP

Who is online

Users browsing this forum: No registered users and 3 guests