Welcome to WebmasterWorld Guest from 54.145.55.135

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Rename file name before upload

     
7:40 am on Mar 17, 2008 (gmt 0)

New User

5+ Year Member

joined:Feb 21, 2008
posts: 9
votes: 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.
7:49 am on Mar 17, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 15, 2004
posts:1867
votes: 0


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

copy($source, $target);

10:07 am on Mar 17, 2008 (gmt 0)

New User

5+ Year Member

joined:Feb 21, 2008
posts: 9
votes: 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.
10:14 am on Mar 17, 2008 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:10563
votes: 16


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...

10:28 am on Mar 17, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 15, 2004
posts:1867
votes: 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');

10:33 am on Mar 17, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 15, 2004
posts:1867
votes: 0


PHP manual Rename [php.net]