I am creating a product listing/image gallery where a user can click a check box and download selected items. I am having trouble getting them to be able to download them. I am using pclzip to zip the files. And I cant even get it to that point yet.
<?php
//if the form has been submitted
if(isset($_POST['submit']))
{
//automatically assign variables
foreach($_POST as $key=>$value)
{
//if an info boxes was checked,
//this will give as array called $info,
//containing the product numbers for each selected item
//same goes for hires and video
if(!empty($_POST[$key]))
{
//list safe keys
if($key=="hires"||$key=="info"||$key=="video")
{
//assign var name based on key name
${$key}=$_POST[$key];
}
}
}
//we can now see what was checked, and do anything we want with each item
if(isset($hires))
{
echo "<h3>Photos requested:</h3>";
foreach($hires as $file)
{
echo $file . "<br />";
}
}
if(isset($info))
{
echo "<h3>Info requested:</h3>";
foreach($info as $file)
{
echo $file . "<br />";
}
}
if(isset($video))
{
echo "<h3>Videos requested:</h3>";
foreach($video as $file)
{
echo $file . "<br />";
}
}
echo "<hr />";
}
//here we echo out all the products
//echo out form and title
echo "<br /><h2>Products:</h2>";
echo "<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\" />";
//define products directory
$dir="products";
//define directory handler
$dh=opendir($dir);
//read through the directory
while(($file=readdir($dh))!==false)
{
//if the file is not . or .., do stuff with it
if($file!=="."&&$file!=="..")
{
echo '<div id="directory">';
echo "<br /><span style=\"font-weight:bold;\">$file</span><br /><br />";
//echo image with hi_res link
echo '<div id="thumb">';
echo "<img src=\"$dir/$file/thumb$file.jpg\" alt=\"\" />";
echo "<a href=\"$dir/$file/hires1-$file.jpg\" rel='shadowbox' alt=\"\" />Enlarge</a><br /><br />";
echo "</div>";
echo '<div id="productdescription">';
$text = file_get_contents("$dir/$file/$file.txt");
echo $text;
echo "</div>";
echo '<div id="downloadcontent">';
echo "<input type=\"checkbox\" name=\"hires1[]\" value=\"hires1-$file\" /> High Res Photo 1 <br />";
echo "<input type=\"checkbox\" name=\"lores1[]\" value=\"lores1-$file\" $disabled /> Low Res Photo 1 <br />";
echo " <input type=\"checkbox\" name=\"hires2[]\" value=\"hires2-$file\" $disabled /> High Res Photo 2 <br />";
echo "<input type=\"checkbox\" name=\"lores2[]\" value=\"lores2-$file\" $disabled /> Low Res Photo 2<br />";
echo "<input type=\"checkbox\" name=\"productinstructions[]\" value=\"$file\" $disabled /> Product Instructions<br />";
//check if video file exists, assign $disabled to either nothing or the disabled property
$disabled=(file_exists("$dir/$file/video$file.mov")) ? "" : "disabled=\"disabled\"";
echo "<input type=\"checkbox\" name=\"video[]\" value=\"video-$file\" $disabled /> Video<br />";
echo "<input type=\"checkbox\" name=\"misc1[]\" value=\"$file\" $disabled /> Misc<br />";
echo "<input type=\"checkbox\" name=\"misc2[]\" value=\"$file\" $disabled /> Misc";
echo "</div>";
echo "<hr />";
echo "</div>";
}
}
//submit button
echo "<input type=\"submit\" name=\"submit\" style=\"position:relative;left:100px;\" />";
echo "</form>";
require_once("pclzip.lib.php");
$zip=new PclZip("archive.zip");
$files=array("file.txt","file2.txt");
$handler=$zip->create($files);
if ($handler==0)
?>
I also would like to be able to do a download all from that category. How, would I go about doing that?
The other issue I have is getting the checkboxes to function properly. I want them disabled if there is no content for that box and enabled if there is. Currently I have a video in the last product on the screen shot and it enabled video and misc , misc. I dont want the misc to be enabled there is no content for them. How can I make this function properly.
Matt