how to convert in zip folder using php script
Demo here
My this code demo you how to convert any file/files into .zip format using php code.
step 1/4 – Saveas index.php:
<script language=”javascript” type=”text/javascript”>
function jayjava1()
{
var str = document.form1.str.value;
str = str.split(“,”);
for(var i = 0; i<str.length; i++)
{
str[i] = str[i];
//each string is taken one by one in the string array
//alert(str[i]);
}
//alert(str);
document.form1.action=’ziper.php?name=’+str;
document.form1.submit();
//document.form1.action=’abc.php’;
//document.form1.submit();
}
</script>
<form name=”form1″ method=”post” action=”<?php echo $_SERVER['PHP_SELF'] ?>” onsubmit=”return jayjava1(); “>
Enter file name that want to convert in pdf(If more then one file then comma seperated only):<br /><input type=”text” name=”str” size=”120″ value=”1.jpg,2.jpg,3.jpg,4.jpg,5.jpg,6.jpg,img.jpg,7450.pdf,OHHH_NO.wmv,Shankh.mp3″ />
<input type=”submit” name=”convertZip” value=”convertZip”>
</form>
step 2/4 -Saveas ziper.php:
<?php
header(“Content-type: application/zip”);
$tempNmae = time().”.zip”;
header(‘Content-Disposition: attachment; filename=”‘.$tempNmae.’”‘);
$source = “sourceFiles/”;
$name = htmlspecialchars($_REQUEST[name]);
$name = explode(“,”,$name);
include(“zip.lib.php”);
$ziper = new zipfile();
foreach($name as $k)
{
//$zippingFiles= $source.$k.”,”;
$zippingFiles= $source.$k;
$ziper->addFiles(array($zippingFiles));
}
//$zippingFiles = substr($zippingFiles, 0, -1);//removing last coma
$ziper->addFiles(array($zippingFiles));
//$ziper->addFiles(array(“sourceFiles/m.pdf”,”sourceFiles/img.jpg”));
$ziper->output($tempNmae);
echo file_get_contents($tempNmae); //Write file in string format
unlink($tempNmae); //Delete the file
?>
step 3/4 -Saveas zip.lib.php:
download here entire code
step 4/4 -Saveas sourceFiles (entire source files here to be zipped):
download here entire code