简体   繁体   中英

Why ZipArchive working not correct?

This is my code zip 1 file:

 $zipname="C:/xampp/htdocs/test/5/JPN/5/5_1.0.pdf.zip"
    $zip = new ZipArchive;
         $zip->open($zipname, ZipArchive::CREATE);                     
         $zip->addFile("C:/xampp/htdocs/test/5/JPN/5/5_1.0.pdf");       
         $zip->close();

But it zip from folder C:\\ 在此处输入图片说明

Why ZipArchive working not correct?

You need to pass two parameters in the addFile function.

According to the documentation

bool ZipArchive::addFile ( string $filename [, string $localname ] )

filename The path to the file to add.

localname local name inside ZIP archive.

This means that the first parameter is the path to the actual file in the filesystem and the second is the path & filename that the file will have in the archive.

The following code will work for you

$zip->addFile("C:/xampp/htdocs/test/5/JPN/5/5_1.0.pdf", "5_1.0.pdf");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM