Unzip File using PHP
you could use this program to unzip your zip files.
First create the interface for file submitting for extraction as bellow.
<td> <form name= "Myform" enctype="multipart/form-data" action="upload.php" method="POST" onsubmit="return ExtensionsOkay();"/> <input type="hidden" /> Extract File:</td><td> <input name="file" type="file" /></td><td> <input type="submit" value="Extract File" /> </form></td> |
Then create 2 folders namely zip and extracted.
There after create following upload.php and then you can extract zip files now.
<html> <body> <?php $target_path = "zip/"; $target_path = $target_path . basename( $_FILES['file']['name']); if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) { echo " ". basename( $_FILES['file']['name']). " </Br>"; $filename=basename( $_FILES['file']['name']); } else { echo "There was an error uploading the file, please try again!"; } $zip = new ZipArchive; $res = $zip->open("zip/$filename"); if ($res === TRUE) { $zip->extractTo('extracted/'); $zip->close(); echo 'Unzip was successful'; } else { echo 'Unzip was not successful'; } ?> <?PHP $folder = "extracted/"; $handle = opendir($folder); while ($file = readdir($handle)) { $files[ ] = $file; } closedir($handle); foreach ($files as $file) { echo '<li><a href="extracted/'.$file.'">'.$file.'</a></li>'; } ?> </body> </html> | Printable_199134522006.zip Unzip was successful |
No comments:
Post a Comment