CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Other Programming Languages: PHP:
renaming file while upload

 



tolearn
Novice

May 3, 2006, 2:52 AM

Post #1 of 4 (27878 views)
renaming file while upload Can't Post

Hi

I have to upload an image file to a file server using php.

While uploading the file has to be renamed.

How to rename a file in php while uploading?


ysawant
Novice

Jul 16, 2007, 2:54 AM

Post #2 of 4 (27598 views)
Re: [tolearn] renaming file while upload [In reply to] Can't Post

first upload the file to the server and then rename it

cheers

yogesh


santhosh_89
Novice

May 4, 2009, 12:59 AM

Post #3 of 4 (24789 views)
Re: [tolearn] renaming file while upload [In reply to] Can't Post

Hello dear,

When you are uploading a file through file browser,You could have got the actual file name with content from $_FILES["file_3"]["tmp_name"],
Any way you are going to move the file from temporary directory to
your current directory,So you can use new name while using move_uploaded_file.

Example:
my actual file name is :santhosh.txt
In temporary directory you will get some file name: asdhgfha.txt
(it is equal to santhosh.txt)
as following i changed actual file name to abc.txt.

move_uploaded_file($_FILES["file_3"]["tmp_name"],"abc.txt");

In Reply To


santhosh_89
Novice

May 4, 2009, 1:07 AM

Post #4 of 4 (24787 views)
Re: [tolearn] renaming file while upload [In reply to] Can't Post

Next way is using rename function.previous way when you are renaming
the file you should have generate the file name dynamically,it should not be a hard coded.Please mind it.It is very important other wise will be losing your data,, I gave simple example,Butter you can generate new algorithm to maintain the unique file name,,,,,,,,

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives