This is the code I am using to upload file and then it seam not to work. I have tried forcing it to download and I get a blank zip file. When I extract, I get a .cpgz file.
The zip file seam to be created, but the uploaded files are not getting inside the zip file i have updated the code, this is how the entire code look like
<?php
if(isset($_POST['createpdf']))
{
$file_folder = "files/"; // folder to load files
$zip = new ZipArchive(); // Load zip library
$zip_name = "upload/".time().".zip"; // Zip name
if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){
// Opening zip file to load files
$error .= "* Sorry ZIP creation failed at this time<br/>";
}
foreach($_FILES['file']['tmp_name'] as $k => $filesuploaded) {
$fname = $_FILES['name'][$k];
$ftmpname = $filesuploaded;
$zip->addFromString(basename($fname),
file_get_contents($ftmpname));
}
$zip->close(); }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upload As Zip</title>
</head>
<body>
<center><h1>Create Zip</h1></center>
<form name="zips" method="post" action="" enctype="multipart/form-data">
<?php if(!empty($error)) { ?>
<p style=" border:#C10000 1px solid; background-color:#FFA8A8; color:#B00000;padding:8px; width:588px; margin:0 auto 10px;"><?php echo $error; ?> </p>
<?php } ?>
<table width="600" border="1" align="center" cellpadding="10" cellspacing="0" style="border-collapse:collapse; border:#ccc 1px solid;">
<tr>
<td width="33" align="center">*</td>
<td width="117" align="center">File Type</td>
<td width="382">File Name</td>
</tr>
<tr>
<td align="center"><input type="file" name="file[]" /></td>
<td align="center"><img src="files/image.png" title="Image" width="16" height="16" /></td>
<td>flowers.jpg</td>
</tr>
<tr>
<td align="center"><input type="file" name="file[]" /></td>
<td align="center"><img src="files/image.png" title="Image" width="16" height="16" /></td>
<td>fun.jpg</td>
</tr>
<tr>
<td align="center"><input type="file" name="file[]" /></td>
<td align="center"><img src="files/doc.png" title="Document" width="16" height="16" /></td>
<td>9lessons.docx</td>
</tr>
<tr>
<td align="center"><input type="file" name="file[]" /></td>
<td align="center"><img src="files/pdf.png" title="pdf" width="16" height="16" /></td>
<td>9lessons.pdf</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="submit" name="createpdf" style="border:0px; background-color:#800040; color:#FFF; padding:10px; cursor:pointer; font-weight:bold; border-radius:5px;" value="Upload" />
<input type="reset" name="reset" style="border:0px; background-color:#D3D3D3; color:#000; font-weight:bold; padding:10px; cursor:pointer; border-radius:5px;" value="Reset" />
</td>
</tr>
</table>
</form>
</body>
</html>