renaming image files

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
nfrandsen
Forum Newbie
Posts: 6
Joined: Fri Nov 21, 2008 4:42 am

renaming image files

Post by nfrandsen »

hi,
im trying to let users upload a profile picture of themselves on a simple website I am creating. I want the picture to be renamed to their userid number and placed in a directory containing all other profile pics, therefore I use the zend form rename filter, BUT, i can't figure out how to make it keep the original file extension:

->addFilter('Rename', '/Applications/xampp/xamppfiles/htdocs/places/web_root/img/profile/' . (int)Zend_Auth::getInstance()->getIdentity()->id);

this works fine, except it creates the file without a filename extension. Sure i could add a . '.jpg' to the end of that and it would create a jpg file but then it would also rename .gif and .png. how can i flexibly rename the filename but keep the file extension?
Thanks a lot for the help!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: renaming image files

Post by pickle »

I'm not sure how to do this with just Zend code. Usually, I'd run it through getimagesize() to determine what type of file it is, then tack on the appropriate extension after renaming.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply