Tôi đang cố gắng sử dụng php để tạo tệp zip (được thực hiện từ trang này - http://davidwalsh.name/create-zip-php), tuy nhiên bên trong tệp zip là tất cả tên thư mục chính tệp đó.php tạo zips mà không cần đường dẫn đến tệp bên trong zip
Có thể chỉ có tệp bên trong mã zip trừ tất cả các thư mục không?
Dưới đây là mã của tôi:
function create_zip($files = array(), $destination = '', $overwrite = true) {
if(file_exists($destination) && !$overwrite) { return false; };
$valid_files = array();
if(is_array($files)) {
foreach($files as $file) {
if(file_exists($file)) {
$valid_files[] = $file;
};
};
};
if(count($valid_files)) {
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
};
foreach($valid_files as $file) {
$zip->addFile($file,$file);
};
$zip->close();
return file_exists($destination);
} else {
return false;
};
};
$files_to_zip = array('/media/138/file_01.jpg','/media/138/file_01.jpg','/media/138/file_01.jpg');
$result = create_zip($files_to_zip,'/...full_site_path.../downloads/138/138_files.zip');
thử '-D' switch (chữ hoa!) – drudge