![]() |
Rename a file before compressing it with ZIP - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Rename a file before compressing it with ZIP (/showthread.php?tid=38223) |
Rename a file before compressing it with ZIP - El Forum - 02-02-2011 [eluser]Unknown[/eluser] Hello everyone, I was looking into the ZIP library as I wanted my users to be able to download several files at once on my site, the library works perfectly (as most CI stuff do) but I had a little problem: The file had their unique name that I use to make sure I can find them in the DB.What I wanted to do is rename the files with their original name before I put them in the Zip. I added this function to the zip library: Code: function rename_and_read_file($path, $new_name, $preserve_filepath = FALSE) I'm sure this could be optimized but as is it does the job. In my controller I use: Code: function download_bulk($file_ids) As you can imagine (I'll spare the code for those as they depend on your implementation) - the find_file(file_id,user_id) return the full path to the file as it is on the disk (with its unique name) or false if the file cannot be found (or you don't have ownership) - the get_full_filename($file_id) is my files_model returns the originial name as a string like: myfile.pdf - the $this->user_id is because I create a global variable in the class so I don't have to read the session user_id all the time. Don't know if it is worth it though in terms of performance. I hope this helps. I'm open to comments and improvement on this.. For example I wonder if there is a smart way to check if two of the files have original name.. what happens when they are both put in the Zip then.. Cheers Antony Rename a file before compressing it with ZIP - El Forum - 02-02-2011 [eluser]Unknown[/eluser] I forgot to say that ideally you would not change the Zip library per sey but really extends it through your own library: application/libraries/MY_Zip.php the codeigniter manual on this is pretty straight forward cheers |