updating file names

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
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

updating file names

Post by hame22 »

Hi all

one of our employees has added files to our site with spaces rather than hyphens. This measn we are experiencing problems when people using mozilla try to download one of these files.

Is it possibe to produce a script which takes the value of the file name (which is stored in a database field) and places hyphens, '-' instead of a space and then updates with this new value?


thanks in advance
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Yes, it's possible.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Yeah. Just grab the name from the database, use str_replace() to fix the spaces, then use PHP's rename() function to rename all the files. And then update the value in the database so that they're correct too.

And finally make sure whatever script you're using to upload files to your site doesn't let it happen again.
Post Reply