0

I am compressing directories and sub directories using PHP zip library. Everything is working fine except renaming files under sub directories. This code is renaming the files successfully in root directory

$zip->addFromString(basename($file), $download_file);
$zip->renameName(basename($file), 'nicename.mp3');

but it is not renaming files in sub directory. Can anybody assist please ?

I have taken this code from Here

Community
  • 1
  • 1
  • "I am compressing directories and sub directories" ....yet you're using ZipArchive::addFromString(). Is there a (good) reason for that? – VolkerK Jun 13 '16 at 11:36
  • I have used Ammar Qala code from http://stackoverflow.com/questions/1334613/how-to-recursively-zip-a-directory-in-php – Aamir Saeed Jun 13 '16 at 12:11
  • My objective is 1. Create unique download folder for each user **Done** 2. Zip folders / sub folders and files **Done** 3. Rename files **Working for root but not working for sub folder** 4. Download the zip folder **Done** This is what I have so far https://docs.google.com/document/d/1P8majqQF3VoChHxDty84vRX6UkTF4fuHqJcbQzNMVE8/edit?usp=sharing – Aamir Saeed Jun 13 '16 at 12:32
  • Why do you provide the "wrong" name in the first place? Just add the files via [::addFile](http://docs.php.net/manual/en/ziparchive.addfile.php) and provide the name you want the entry to have within the archive as the second parameter (no need the rename it afterwards). – VolkerK Jun 13 '16 at 14:13
  • I am storing the name as timestamp i.e 1465467856.jpg in DB. I want user to see the proper name of file if he downloads. Okay I try addFile. Thanks. – Aamir Saeed Jun 13 '16 at 15:02
  • It looks like addFile has done the trick. Thanks. – Aamir Saeed Jun 14 '16 at 08:55

0 Answers0