Jump to content

How to rename an Uploaded file?


lopes_andre

Recommended Posts

Hi,

 

I need to upload files rename the files as ("name_of_file" . "TIMESTAMP" . ".doc") or other file termination...

 

I have a function that upload sucessfully the files, but I don't know how to rename the files.

 

function uploadFile() {
global $attachments;
while(list($key,$value) = each($_FILES[images][name]))
			{

				if(!empty($value))
				{
						$filename = $value;
						array_push($attachments, $filename);
						$dir = "$way" . "$filename";
						chmod("$way",0777);
				         $success = copy($_FILES[images][tmp_name][$key], $dir);
				}

			}
									    
				           if ($success) {
							echo " Files Uploaded Successfully<BR>";
						#############	SendIt();

								}else {
										exit("Sorry the server was unable to upload the files...");
									}

}

 

How can I rename the files?

 

 

Best Regards,

André.

Link to comment
https://forums.phpfreaks.com/topic/144587-how-to-rename-an-uploaded-file/
Share on other sites

Hello, :)

 

Have you tried to change this line:

$success = copy($_FILES[images][tmp_name][$key], $dir);

 

to:

$success = copy($_FILES[images][tmp_name][$key], "$dir/$new_file_name");

 

The syntax of copy command is:

copy($old_file, $new_file_name);

 

If your question is how to make timestamp string for file name it would be like this:

$new_file_name = 'name_of_file' .date("mdY") .'.doc'; //result name_of_file02102009.doc              

       

 

I hope this will be useful for you. ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.