I’m making a website, using codeigniter, that will enable users to download files a bit like gmail. By that I mean that the user can download only 1 file or all files in a zip folder.
Because there will be many files, I have encoded their names to avoid duplicates and stored their original names in a database which returns me an array like this:
Array
(
[0] => Array
(
[file_id] => 2
[file_name] => v6_copy.pdf
[file_path] => uploads/4/d5/67697ff58d09d3fb25d563bf85d3f1ac.pdf
)
[1] => Array
(
[file_id] => 3
[file_name] => v4_copy.pdf
[file_path] => uploads/7/cf/38212079635e93a8f8f4d4a3fc2a11ff.pdf
)
)
What I need to do is, get each file, rename them to their original names and then zip it in one zip. I’m currently trying to use the codeigniter zip helper, but I can’t seem to be able to rename the files.
foreach ($query->result() as $row) // This returns what you see above
{
// I need to rename the file somewhere here
$this->zip->read_file($row->filename);
}
$this->zip->download('files_backup.zip');
Is there a way to do this without creating manually a directory, copying the files, renaming them and then zipping the file?
Any help most appreciated.
Thanks to @Gordon ‘s answer, I found a solution.
He is completely right about Codeigniter not being able to rename a file, but I found a really quick change to the library and it seems to be working.
If you go to your system>librairies->Zip.php like mentioned by @Gordon, search for “read_file” and you’ll find the function.
Then I simply added a argument to the function and modified some of the code thereafter, see below:
I hope this helps others. Thanks again @Gordon