user580523
user580523

Reputation:

PHP ZIP generating Same File Size

I'm using PHP to generate and force download a ZIP file that contains a sequence of photos listed from a database table.

Everything seems to be working great, but I can't seem to figure out why the photos keep downloading at the same file size.

I'm assuming the files arn't being compressed correctly, I thought it might be the headers but I'm just not sure.

Could anybody shed some light on my problem?

CODE:

require ("zipfile.inc.php");
$zipfile = new zipfile();
$filedata = implode("", file("zipfile.inc.php"));

$getspdi = mysql_query("SELECT * FROM `wedding_photos` WHERE `user_hash` = '$logged[ip]' ORDER BY `id` DESC LIMIT 0, 1000") or die(mysql_error());
$getspd = mysql_fetch_array($getspdi);

while ($photos = mysql_fetch_array($getspdi)) {
     $zipfile->add_file($filedata, "$photos[img]");
}

header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");

header("Content-disposition: attachment; filename=szipfile.zip");
echo $zipfile->file();

I'm using an exsisting class called "zipfile.inc.php" (http://www.devco.net/code/zipfile.inc.txt).

Any help would be appreciated,

Thanks.

Upvotes: 0

Views: 267

Answers (2)

Pekka
Pekka

Reputation: 449395

This line makes no sense:

 $zipfile->add_file($filedata, "$photos[img]");

With that, you are adding the contents of zipfile.inc.php and giving it the image's name.

You need to fetch the actual image data from somewhere.

Upvotes: 2

Emil Vikström
Emil Vikström

Reputation: 91912

Most image formats are already compressed. That includes JPEG, PNG and GIF. You cannot compress files in such formats much further using ZIP compression. Indeed, some of the formats are already using the same compression algorithm, which makes it virtually impossible to decrease the size anything at all.

Upvotes: 2

Related Questions