我正在尝试构建一个应用程序,我必须上传一个zip文件并提取其内容,然后将它们放入mysql数据库。我这样做了一半成功..这是将zip文件上传到名为的临时文件夹上传....现在我想访问每个单独的内容,并将其形成数据库并将真实内容移动到原始上传文件夹中说real_uploads ....我正在尝试,但我无法弄清楚如何继续.... 以下是我的代码........
<?php
if(isset($_FILES['zip'])){
//defined an error erray
$errors=array();
$zip = new ZipArchive();
//print_r($_FILES['zip']);
//taking the extention of the last file (in lower case) of the zip file
if(strtolower(end(explode('.',$_FILES['zip']['name'])))!=='zip'){
$errors[]="this is not a zip file";
//echo "file is not opened";
}
//if file bigger than 100mb
if($_FILES['zip']['size']>104857600){
$errors[]="there is a size limit of 100 mb";
}
if($zip->open($_FILES['zip']['tmp_name'])===FALSE){
echo "file is opened";
$errors[]="failed to open zip file";
}
if(empty($errors)){
$path=$zip->extractTo('uploads');
print_r($zip);
$extracted_files=array();
for($i=0;$i<$zip->numFiles;++$i){
$zip_name=$zip->statIndex($i);
$extracted_files[]=basename($zip_name['name']);
$zip->close();
}
}
?>
<html>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<div>
<input type="file" name="zip"/>
<input type="submit" value="Upload"/>
</div>
</form>
</body>
</html>
<?php
if(isset($errors)){
if(empty($errors)){
echo 'your files '.implode("<br> ",$extracted_files).' been uploaded';
}else{
foreach($errors as $error){
echo '<p>'.$error.'</p>';
}
}
}
?>