PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
/* The directory you wish to scan for files or create an array in some other manner */
$target=__DIR__.'\\MyZipArchive.zip';
echo var_dump($target);
$id = $_GET['id'];
$query = "SELECT photo, photoprimary FROM products WHERE id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$files_to_zip = explode('|', $row['photo']);
$files_to_zip[] = $row['photoprimary'];
$image_path = __DIR__ . '\\images\\productphotos\\';
echo var_dump($image_path);
// Now we go through each file in our array
foreach ($files_to_zip as $index => $file) {
// and inject that path to the beginning of each file we pulled from the database
$files_to_zip[$index] = $image_path . $file;
}
if( $target ) {
/* Zip the contents: use `true` to overwrite existing zip */
$result=create_zip( $files_to_zip, $target, true );
/* Send the file - zipped! */
if( $result ) call_user_func( 'sendfile', 'MyZipArchive.zip', $target );
}
// Now we go through each file in our array
foreach ($files_to_zip as $index => $file) {
// and inject that path to the beginning of each file we pulled from the database
$files_to_zip[$index] = $image_path . $file;
}
echo var_dump($files_to_zip);
The first entry is obviously wrong as there's no file specified. Are you getting the right values back from your query? Also, does the second value in that array exist in your file system? Finally, can the web server write to your site directory to create the zip archive?
Goodness me, what an idiot.
Damn thing had no gallery images.
So I have added some gallery images, and the main one was there.
Now when I run it with var_dump, I get this:
[text]array(4) { [0]=> string(73) "C:\xampp\phpMyAdmin\site\images\productphotos\70581465241v6.jpg" [1]=> string(73) "C:\xampp\phpMyAdmin\site\images\productphotos\15587545140s1.jpg" [2]=> string(56) "C:\xampp\phpMyAdmin\site\images\productphotos\" [3]=> string(77) "C:\xampp\phpMyAdmin\site\images\productphotos\57875142478355571.jpg" } string(51) "C:\xampp\phpMyAdmin\site\MyZipArchive.zip" [/text]
The first two are fine in that lot, but why is the third one with no photo in it, then the first has the pic which I think is the primary photo.
Besides that, it still doesn't work. Blank screen comes up (without the error report) and no popup to download a zip.
Is this meant to create a ZIP on the server, or just give one to download "on the fly"?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis wrote:Now when I run it with var_dump, I get this:
[text]array(4) { [0]=> string(73) "C:\xampp\phpMyAdmin\site\images\productphotos\70581465241v6.jpg" [1]=> string(73) "C:\xampp\phpMyAdmin\site\images\productphotos\15587545140s1.jpg" [2]=> string(56) "C:\xampp\phpMyAdmin\site\images\productphotos\" [3]=> string(77) "C:\xampp\phpMyAdmin\site\images\productphotos\57875142478355571.jpg" } string(51) "C:\xampp\phpMyAdmin\site\MyZipArchive.zip" [/text]
The first two are fine in that lot, but why is the third one with no photo in it
Trailing | character in the DB field? You might want to rtrim those out before exploding. Alternately, check the resultant array and remove empty values.
simonmlewis wrote:Besides that, it still doesn't work. Blank screen comes up (without the error report) and no popup to download a zip.
Is create_zip still returning false? Is a zip file being created? Need to know where it fails before we can determine why it fails.
simonmlewis wrote:Is this meant to create a ZIP on the server, or just give one to download "on the fly"?
I am not sure that it's because of the trailing |, because it wasn't working beforehand, when there was no images in $row->photo anyway. But I can query I think to see if there is a | on the end, and remove it. Because yes there is one.
No Zip is being created.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis wrote:I am not sure that it's because of the trailing |, because it wasn't working beforehand, when there was no images in $row->photo anyway. But I can query I think to see if there is a | on the end, and remove it. Because yes there is one.
create_zip would have removed that entry as invalid, but you specifically asked how it was there to begin with, so I took a stab at it.
simonmlewis wrote:No Zip is being created.
Let's check the value of $valid_files after the foreach loop in create_zip. Is it empty or does it contain values?
The array being populated is a good sign. The file paths are correct and create_zip knows the files exist. Now for some reason it's not able to create the zip file. First thing that comes to mind is write permissions, but I haven't worked with Windows in ages and don't know how permissions are implemented there.