homepage Welcome to WebmasterWorld Guest from 184.73.104.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Rename file name before upload
mcnika

5+ Year Member



 
Msg#: 3602657 posted 7:40 am on Mar 17, 2008 (gmt 0)

Hi.
I need PHP code, that will let me rename file, when upload it to an exactly folder.I mean when i choose the file that i'll upload it, it must change the name and then upload it.

 

Habtom

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3602657 posted 7:49 am on Mar 17, 2008 (gmt 0)

If you have the copy function somewhere on your upload script, you can rename the file as you copy it.

copy($source, $target);

mcnika

5+ Year Member



 
Msg#: 3602657 posted 10:07 am on Mar 17, 2008 (gmt 0)

Suppose that you have "flower.jpg" image in the folder.
I click on Browse and choose image with the same name "flower.jpg"
and click submit.The code must check if there is a such file on the folder, if yes rename it and upload. The checking code I've already written.
The function that you wrote would help me if I'd like to change the name of the first image.

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 3602657 posted 10:14 am on Mar 17, 2008 (gmt 0)

welcome to WebmasterWorld [webmasterworld.com], mcnika!

you cannot change the name of a file before you upload it.

when you upload a file the script must create a file and write the uploaded data to the file.
you can name the newly created file anything you like when you create it...

Habtom

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3602657 posted 10:28 am on Mar 17, 2008 (gmt 0)

The function that you wrote would help me if I'd like to change the name of the first image.

if yes rename it and upload

Are you trying to name the existing file, if there the new file is having the same file name as the one already in the server?

rename('flower.jpg', 'flower2.jpg');

Habtom

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3602657 posted 10:33 am on Mar 17, 2008 (gmt 0)

PHP manual Rename [php.net]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved