Rajesh
Rajesh

Reputation: 163

How to move a file in to zip compressed format

i am using move_upload_file function to move the file to my folder,its work fine but i want compressed zip format.plz any body help...

Upvotes: 1

Views: 1774

Answers (2)

Ravinder Payal
Ravinder Payal

Reputation: 3041

Take a look at the Zip extension:

http://www.php.net/manual/en/zip.examples.php

I looked at the code you linked to (it would have been good if you included it in the question) and made a few changes:

$nameFile = $_FILES['file']['name'];
$tmpName = $_FILES['file']['tmp_name'];
$download_folder = './files/';

$zip = new ZipArchive();
$fileconpress = $download_folder.$nameFile.".zip";

$conpress = $zip->open($fileconpress, ZIPARCHIVE::CREATE);
if ($conpress === true)
{
    $zip->addFile($tmpName);
    $zip->close();
    echo $fileconpress."<br/>";
    echo "yess !! Success!!!! ";
}
else echo " Oh No! Error";

The important part and likely what's causing your error is $download_folder. You need to define the path of where you want to save the file.

I also removed the fread(), you can just load the file straight into the zip object with addFile()

Upvotes: 0

Related Questions