-2

I am trying to create a page that simply zips files, that's all there is to it. I added the check to make sure the method was actually being called, and it is, I am seeing the "ok" when the code is run, however, no ZIP file is being created.

Any help would be appreciated. I can confirm that those files exist. (They are in relation to where the php file is)

$zip = new ZipArchive;
if ($zip->open('/files/custom.zip', ZipArchive::CREATE) === TRUE) {
    $zip->addFile('/files/textures/16/default/pack.mcmeta');
    $zip->addFile('/files/textures/16/default/pack.png');
    $zip->close();
    echo "ok";
} else {
    echo "failed";
}
jww
  • 97,681
  • 90
  • 411
  • 885
  • 1
    So, you're sure those paths are correct? Should they not be `files/custom.zip` (without the leading `/`)? – gen_Eric Jan 02 '15 at 19:39
  • [Documentation says](http://php.net/manual/en/ziparchive.open.php): Returns true on succes or and error code on failure. Instead of echoing `failed`, you could check the actual return value and get a hint about the cause. – GolezTrol Jan 02 '15 at 19:43

1 Answers1

0

try this

<?php
$zip = new ZipArchive;
if ($zip->open('/files/custom.zip') === TRUE) {
    $zip->addFile('/files/textures/16/default/pack.mcmeta', 'pack.png');
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>
sanoj lawrence
  • 951
  • 5
  • 29
  • 69