lopes_andre Posted February 10, 2009 Share Posted February 10, 2009 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 More sharing options...
anthylon Posted February 10, 2009 Share Posted February 10, 2009 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. Link to comment https://forums.phpfreaks.com/topic/144587-how-to-rename-an-uploaded-file/#findComment-758763 Share on other sites More sharing options...
coder_ Posted February 10, 2009 Share Posted February 10, 2009 Or you can use move_uploaded_file() function. just set the name of the temporary file and location with new file name and that's it. move_uploaded_file("/path/to/tmp_folder/tmp_name", "/path/to/new_folder/new_name.ext"); Link to comment https://forums.phpfreaks.com/topic/144587-how-to-rename-an-uploaded-file/#findComment-758784 Share on other sites More sharing options...
lopes_andre Posted February 10, 2009 Author Share Posted February 10, 2009 Thanks a lot. It worked! Link to comment https://forums.phpfreaks.com/topic/144587-how-to-rename-an-uploaded-file/#findComment-758810 Share on other sites More sharing options...
anthylon Posted February 10, 2009 Share Posted February 10, 2009 LOL Marking post as SOLVED would help Cheers Link to comment https://forums.phpfreaks.com/topic/144587-how-to-rename-an-uploaded-file/#findComment-758860 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.