Ok, I've figured out my problems by myself, and I'm sharing the solution for those who want.
- Make it generic (i.e. I want to have that makezip.php in root folder. I've a file manager, and everytime I call this script from some location (ex. www.domain.com/files/media/images/ it gets that folder).
I modified the code on index.php, and made a few changes on zip.php (the file which is handling the zipping process. Simples solution.. Dumb!
1 - index.php - just put a simple link
<a href="zip.php?dirz=HERE_GOES_THE_FOLDER_URL">Download folder as a .zip</a>
2 - zip.php
$directory = $_REQUEST['dirz'];
- Delete the zip after the download (I think I did it well, using the comand unlinkbut I'm not sure that's the right way.
Yes, it's correct. (on zip.php)
unlink($ZIPNAME);
- Remove that . and .. folder that the zip gets too.
$direct = array_diff(scandir($directory), array(".","..","error_log"));
foreach($direct as $file){
if(is_file($directory.'/'.$file)){
$zip->addFile($directory.'/'.$file, $file);
}
}
- Export the zip with the name date.hour.directory.zip (ex 18Sep2013_13-26-02_images.zip). I tried to do this $fd = getcwd(); $filename = date("dMY_H:i:s").'_'.$fd.'.zip'; but it didn't worked, it only gets the $fd variable.
Simple as:
$zipname = date("dMY_H-i-s").'_'.basename($directory).'.zip';
Best regards