我正在運行一個腳本,ZIP是一個用戶個人目錄,當請求時。PHP .ZIP對象 - str_replace文件夾路徑?
到該目錄的路徑是:
../temp/useremail/
當ZIP真正下載,這也是如何的文件夾路徑出現在它(這顯然看起來很恐怖)。我希望它只顯示爲:
USEREMAIL/
我試着用str_replace函數,但它是無效的。這裏是我的代碼:
$zip = new ZipArchive();
$exists = file_exists('../temp/' . $email . '/theme-' . $email . '.zip');
$delete = '../temp/' . $email . '/theme-' . $email . '.zip';
if($exists) {
unlink($delete);
}
if ($zip->open('../temp/' . $email . '/theme-' . $email . '.zip', ZIPARCHIVE::CREATE) !== TRUE) {
die("Could not open archive");
}
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("../temp/$email/"));
foreach ($iterator as $key => $value) {
$_key = str_replace("../temp/'.$email.'/", "", $key);
$zip->addFile(realpath($_key), $_key) or die("ERROR: Could not add file: $key");
}
$zip->close();
嘗試'ZipArchive :: renameName' - http://www.php.net/manual/en/ziparchive.renamename.php – scibuff 2012-03-03 12:32:44
快速瀏覽,但它似乎沒有幫助,除非我使用它錯的是。你會如何將其整合到我目前的腳本中? – tctc91 2012-03-03 12:48:09