How do I create a ZIP file from this tutorial?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
How do I create a ZIP file from this tutorial?
We need to provide a link so that admin can click an icon and it downloads all the product images for a product into a ZIP file.
https://davidwalsh.name/create-zip-php
This page seems to be perfect, except that my knowledge is limited, and I don't see how to use this to create a hyperlink to 'run' it and make it download a file.
I can add all the images to the Zip file, it's just the "click to download" but I am stuck on.
https://davidwalsh.name/create-zip-php
This page seems to be perfect, except that my knowledge is limited, and I don't see how to use this to create a hyperlink to 'run' it and make it download a file.
I can add all the images to the Zip file, it's just the "click to download" but I am stuck on.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do I create a ZIP file from this tutorial?
What if you created a link to some PHP script that creates the zip file and starts the download? You could use a GET parameter to specify which product to use when creating the zip.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I create a ZIP file from this tutorial?
Thing is, from what I read, that page is the answer to it. But it doesn't show how to make the array connect with the script, nor what the final $result is for.
I'm sure there is a simple explanation of how to run a hyperlink that triggers it, and generate a "save as". Or via a Form button.
Whether this is what you are saying, I'm not entirely sure. Those on Stackoverflow seem a little aggressive in their language. But have asked all over.
I'm sure there is a simple explanation of how to run a hyperlink that triggers it, and generate a "save as". Or via a Form button.
Whether this is what you are saying, I'm not entirely sure. Those on Stackoverflow seem a little aggressive in their language. But have asked all over.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I create a ZIP file from this tutorial?
This is where I am at for now. Trying to get the images from the field into the array.
Problem is, all my gallery images are in one field with | separating the file names.
(if I built this again, I'd put them in separate table per-row!!).
So I need to put each image into that various, with it's location.
Problem is, all my gallery images are in one field with | separating the file names.
(if I built this again, I'd put them in separate table per-row!!).
So I need to put each image into that various, with it's location.
Code: Select all
$rValue = "";
$query = ("SELECT photo FROM products WHERE id = '$id'");
$result = mysql_query($query);
if ($row = mysql_fetch_array($result)){
$token = strtok($string,"|");
while($token)
{
$rValue = $token;
$token = strtok("|");
}
$token = NULL;
}
return $rValue;
$files_to_zip = array(
'preload-images/1.jpg',
'preload-images/2.jpg',
'preload-images/5.jpg',
'kwicks/ringo.gif',
'rod.jpg',
'reddit.gif'
);Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do I create a ZIP file from this tutorial?
http://php.net/manual/en/function.explode.phpsimonmlewis wrote:This is where I am at for now. Trying to get the images from the field into the array.
Re: How do I create a ZIP file from this tutorial?
So pass the product ID as a GET parameter, use that to grab the photo field, explode on pipe to get your array, create the zip file, and use headers to force download. Should be all you need. Looks like you're on the right track.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I create a ZIP file from this tutorial?
I am. But "explode your pipe to get your array" is something I cannot even get close to grasping it's meaning. Sorry.
I get that you mean you explode using the | to separate it all, but then how do I put that into the array()?
I'm glad people here like yourself, are not as blasted sarcastic as other help forums.
I get that you mean you explode using the | to separate it all, but then how do I put that into the array()?
I'm glad people here like yourself, are not as blasted sarcastic as other help forums.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do I create a ZIP file from this tutorial?
Yes, I mean call explode with | (pipe character) as the delimiter. This will return an array.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I create a ZIP file from this tutorial?
Do you mean like this?
Code: Select all
$query = ("SELECT photo FROM products WHERE id = '$id'");
$result = mysql_query($query);
while ($row = mysql_fetch_object($result))
{
$rValue = $row->photo;
}
$explodephoto = explode("|",$rValue);
$files_to_zip = array(
$explodephoto
);Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I create a ZIP file from this tutorial?
And if so, how do I put the file location into the $explodephoto array?
Secondly, I need to do this for two fields. The one shown, and one with NO explode needed for "photoprimary".
So I would need to add that to the array... somehow.
Secondly, I need to do this for two fields. The one shown, and one with NO explode needed for "photoprimary".
So I would need to add that to the array... somehow.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do I create a ZIP file from this tutorial?
So your sample above:
could be reduced to something like this:
Code: Select all
$rValue = "";
$query = ("SELECT photo FROM products WHERE id = '$id'");
$result = mysql_query($query);
if ($row = mysql_fetch_array($result)){
$token = strtok($string,"|");
while($token)
{
$rValue = $token;
$token = strtok("|");
}
$token = NULL;
}
return $rValue;
$files_to_zip = array(
'preload-images/1.jpg',
'preload-images/2.jpg',
'preload-images/5.jpg',
'kwicks/ringo.gif',
'rod.jpg',
'reddit.gif'
);Code: Select all
$query = "SELECT photo FROM products WHERE id = $id";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$files_to_zip = explode('|', $row['photo']);-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I create a ZIP file from this tutorial?
OMG that is clever. So how do I then add to that lot, the "photoprimary" field as well?
Secondly, how do I add the file location, ie, http://www.site.co.uk/images/productphotos/*.jpg ??
Secondly, how do I add the file location, ie, http://www.site.co.uk/images/productphotos/*.jpg ??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do I create a ZIP file from this tutorial?
photoprimary contains a single value? How to approach that I suppose depends on how it's being used. If it's just another image that you want to include in the zip, you can just append it to the array.simonmlewis wrote:And if so, how do I put the file location into the $explodephoto array?
Secondly, I need to do this for two fields. The one shown, and one with NO explode needed for "photoprimary".
So I would need to add that to the array... somehow.
Example:
Code: Select all
$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'];Re: How do I create a ZIP file from this tutorial?
How do you mean? You wouldn't need this for creating the zip. What's the use case here?simonmlewis wrote:how do I add the file location, ie, http://www.site.co.uk/images/productphotos/*.jpg ??
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I create a ZIP file from this tutorial?
How does it know WHERE those images are coming from?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.