aiwazz
asked on
PHP ZipArchive Creating entire folder path in ZIP Archive
I just wrote a little zip function into my file uploader for my forum to create an archive from the files that have been uploaded during the session. The files locations are different than the scripts that executes the zip function. it works fine but the zip file contains the entire folder structure of my server from /home/ onwards as i have used absolute paths in the function. I do not want the files put in any folders, just at the root of the zip. could anyone help with this? Thank you, first time using the zip function, just recompiled to get it going.
my code:
my code:
// $_CONFIG_DATA['absolute_path'] is server path
// $_CONFIG_DATA['path_to_upload'] is url path
function createzipfile($_FILE_DATA, $_CONFIG_DATA, $_POST_DATA)
{
$zip = new ZipArchive();
$zipname = $_CONFIG_DATA['absolute_path'] . $_CONFIG_DATA['upload_id'] . ".zip";
$zipurl = $_CONFIG_DATA['path_to_upload'] . $_CONFIG_DATA['upload_id'] . ".zip";
if ($zip->open($zipname, ZIPARCHIVE::CREATE) !== TRUE) {
die ("Could not open archive");
}
foreach($_FILE_DATA as $slot => $value){
$file_slot = $_FILE_DATA[$slot]->getFileInfo('slot');
$file_name = $_FILE_DATA[$slot]->getFileInfo('name');
$fpath = $_CONFIG_DATA['absolute_path'] . $file_name;
$zip->addFile($fpath) or die ("ERROR: Could not add file: $fpath");
}
// close and save archive
$zip->close();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER