File Upload - filename of uploaded files - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: File Upload - filename of uploaded files (/showthread.php?tid=10909) |
File Upload - filename of uploaded files - El Forum - 08-18-2008 [eluser]Ornis[/eluser] Uploading a file works fine. However, I would like to give the uploaded file on the server a specific name rather than the name passed over from the source file. Can this be done within the uploading process? Thanks for CodeIgniter - it's just great! File Upload - filename of uploaded files - El Forum - 08-18-2008 [eluser]drewbee[/eluser] In looking through the upload class code, you either have the option to randomize the name or use the original uploaded name. Unfortunately there doesn't appear to be way to set the filename as $this->filename is changed during the do_upload method. Extend it and do it your own way! What I may suggset is extending the do_upload function. Notice:: PSUDO CODE, most likely will not work. This is for a general idea of what needs to be done. Code: function do_upload($filename) This is an easy fix to it. Unfortunately we do double the work to complete this. (putting file then renaming). Ideally it would be better to rename it before the put. The only viable way I see doing this though is extending do_upload with practically the same code except the ability to pass a new file name to it. File Upload - filename of uploaded files - El Forum - 08-18-2008 [eluser]xwero[/eluser] At the moment there is no way to do it during the upload process AFAIK. But without changing the core files you could do something like this Code: // upload file code edit : beaten File Upload - filename of uploaded files - El Forum - 08-29-2008 [eluser]redtuxrising[/eluser] before calling do_upload(), change 'name' element of $_FILES array to whatever you want and that'll do it. Example: Code: //first get the file extension |