Hi,
I have to provide a functionality where my clients can browse images folder on my server and select multiple images to download on their computer.
Could be done by http request and zipping the files.
I would appreciate if anybody can guide me how to create the zip file and point to any site which has a readymade script for zipping the files before download in PHP.
My code so far is
Appreciate any help.
Thanks,
Tewari.
I have to provide a functionality where my clients can browse images folder on my server and select multiple images to download on their computer.
Could be done by http request and zipping the files.
I would appreciate if anybody can guide me how to create the zip file and point to any site which has a readymade script for zipping the files before download in PHP.
My code so far is
Code:
<?
$HOST="abc.com";
$UN="xyz";
$PW="zyx";
$DIR="/images/";
//$FILE="test.txt";
$conn = ftp_connect($HOST);
if(!$conn) {
exit("Could not connect to server: $HOST\n");
}
if(!ftp_login($conn,$UN,$PW)) {
ftp_quit($conn);
exit("Could not log in\n");
}
ftp_chdir($conn,$DIR);
if($_POST['download'] != '')
{
foreach ($_POST['filearrayname'] as $key=>$val)
{
[COLOR=#ff0000] //some code here to create a zip file which has all the selected image files[/color]
$newDirectory = "downloaded";
$movefiles = "mv ".$val." ".$newDirectory;
system($movefiles);
}
//making the zip file available for download
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment;filename=x.zip');
//readfile($val);
unset($_POST['submit']);
ftp_quit($conn);
}
$files = ftp_nlist($conn,".");
?>
<form name = "ftpupdown" action = <? echo $PHP_SELF ?> method = "post"> <table>
<?
for($i=0;$i<count($files);$i++) {
if($files[$i] != "." || $files[$i] != "..")
{
echo "<tr><td><input type = radio name = filearrayname[".$files[$i] ."] value=".$files[$i].">".$files[$i]."</td></tr>";
}
//if(!ftp_get($conn,$files[$i],$files[$i],FTP_ASCII)) {
// echo "Could not download {$files[$i]}\n";
//}
}
?>
<tr><td> <input type = "submit" name="download" value = "Start Download"></td></tr></table></form>
<?
//if(!ftp_put($conn,$DIR.$FILE,$FILE,FTP_ASCII)) {
// echo "Could not upload $FILE\n";
// }
//ftp_quit($conn);
?>
Appreciate any help.
Thanks,
Tewari.