0

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:\ enter image description here

Why ZipArchive working not correct?

D T
  • 3,522
  • 7
  • 45
  • 89
  • Possible duplicate of [How to zip a whole folder using PHP](https://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php) – Arun Kumaresh Aug 28 '17 at 11:56
  • `open()` returns either TRUE or an error code on failure. `addFile()` and `close()` both return false on failure. What do you see if you check the return values from these functions? – Matt Gibson Aug 28 '17 at 13:14

1 Answers1

2

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");