Jump to content

php zipping jpgs on the fly


terrypeck36

Recommended Posts

i am using a very standard script that works for text files but not jpgs, it does not work for gifs either.
the zip is correctly made in a temp directory and i can successfully ftp it and extract intact text files and the jpgs are in the zip, correct original filesize, compressed a little bit but when i extract and open there is no data available or image failed.

has anyone ever had this problem??

any help would be appreciated

here is my code

[code]
<?php
include ('pear/archive_zip.php');

// Create instance of Archive_Zip class, and pass the name of our zipfile
$zipfile = New Archive_Zip('myzipfile.zip');

// Create a list of files and directories
$list = array('test.txt', 'pic.jpg');

// Get temporary directory
if (!empty($_ENV['TMP'])) {
        $tempdir = $_ENV['TMP'];
} elseif (!empty($_ENV['TMPDIR'])) {
        $tempdir = $_ENV['TMPDIR'];
} elseif (!empty($_ENV['TEMP'])) {
        $tempdir = $_ENV['TEMP'];
} else {
        $tempdir = dirname(tempnam('', 'na'));
}

if (empty($tempdir)) { die ('No temporary directory'); }

// Make sure trailing slash is there
$tempdir = rtrim($tempdir, '/');
$tempdir .= '/';

// Make sure temporary directory is writable
if (is_writable($tempdir) == false) {
        die ('Temporary directory isn\'t writable');
}

// Create temp name    for our own directory
$dir = tempnam($tempdir, 'temp');

// Make sure another file or directory doesn't already exist with this name
@unlink($dir);
@rmdir($dir);

// Create directory
mkdir($dir);
$dir .= '/';

// Copy files & directories so relative paths still work
foreach ($list as $item) {
        if (is_file($item)) {
                // Copy file
                copy ($item, $dir . $item);
        } elseif (is_dir ($item)) {
                // Copy directory
                move_directory ($item, $dir . $item, true);
        } else {
                // Invalid file, just ignore
                continue;
        }
}

// Change current working directory, so that the zip file gets created in the temp dir
chdir($dir);

// Create the zip file
$zipfile->create($list);

echo 'Zip file created in ' . $dir;

[/code]
Link to comment
https://forums.phpfreaks.com/topic/31202-php-zipping-jpgs-on-the-fly/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.