Welcome to WebmasterWorld Guest from 54.147.20.131

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Rename file name before upload

     

mcnika

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

5+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

copy($source, $target);

mcnika

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

5+ Year Member



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

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

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



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



PHP manual Rename [php.net]
 

Featured Threads

Hot Threads This Week

Hot Threads This Month