Image Deletion?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Image Deletion?

Post by JPlush76 »

ok I searched this site and the manual but perhaps i was just looking for the wrong thing...

I have an image upload script that works dandy, but I'd like the ability for the user to change their picture, I know how to do it from the database, but how do I clean that file off my server after they change it to the new pic?

mucho gracias
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post by fatalcure »

yup, unlink will do the trick :)

you could also rename the new file to the same name again if they're updating the picture, so it'll take its place.
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

oh really? it will just ovewrite the existing file?

I assumed it would generate an error because the file name is already there

that makes life alot easier
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post by fatalcure »

nope, wont generate an error, unless you spit out an error yourself by actually checking to see if the file exists in the php script, so no other person can upload the same filename and overwrite something you dont want overwritten.
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

that rocks :o

so when they sign up I'll just make sure that username is not already taken and just make the name of the image their username

:lol:
Post Reply