提取zip文件并访问zip文件的每个内容,然后将其移动到php中的新位置
我正在尝试构建一个应用程序,在这个应用程序中,我必须上传一个zip文件并提取其内容,然后将其放入mysql数据库。我成功了一半。这是将zip文件上载到名为uploads的临时文件夹中…现在我想访问每个单独的内容,并将其信息放入数据库中,然后移动将真实内容上传到原始上传文件夹中,表示真实上传…我正在尝试,但我不知道如何继续。。。。 以下是我的代码提取zip文件并访问zip文件的每个内容,然后将其移动到php中的新位置,php,mysql,Php,Mysql,我正在尝试构建一个应用程序,在这个应用程序中,我必须上传一个zip文件并提取其内容,然后将其放入mysql数据库。我成功了一半。这是将zip文件上载到名为uploads的临时文件夹中…现在我想访问每个单独的内容,并将其信息放入数据库中,然后移动将真实内容上传到原始上传文件夹中,表示真实上传…我正在尝试,但我不知道如何继续。。。。 以下是我的代码 <?php if(isset($_FILES['zip'])){ //defined an error erray $errors
<?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>';
}
}
}
?>
请更具体地说明此代码的错误行为,或您试图添加的内容。代码只会上载上载文件夹中的文件,并显示上载文件的名称。。。。