上传 Zip 文件并解压缩 Zip [英] Upload Zip File and Extract the Zip
本文介绍了上传 Zip 文件并解压缩 Zip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表单 (HTML),它将文件提交给 PHP 脚本,该脚本将文件重命名为 ZIP,将其存储在一个文件夹中(随机名称),然后提取该文件.
I have a form (HTML) which submits a file to a PHP script which renames the file to ZIP, stores it in a folder (random name) and then extracts that file.
文件已上传.该文件夹已正确创建.文件被正确重命名.
The file gets uploaded. The folder is created correctly. The file gets renamed correctly.
解压失败.
这是我的表格:
<form action="up.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
Select file
<input name="ufile" type="file" id="ufile" size="50" />
<input type="submit" name="Submit" value="Upload" />
</form>
这里是 PHP 脚本 - up.php
Here is the PHP script - up.php
$file_name = $HTTP_POST_FILES['ufile']['name'];
$random_digit=rand(0000,9999);
$new_file_name=$random_digit.".zip";
mkdir($random_digit, 0777, true);
$path= $random_digit.'/'.$new_file_name;
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "The upload is successful<BR/>";
echo "File Renamed to: ".$new_file_name." for processing.<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
echo "<strong><a style='color:#6A8DBC; text-decoration:none' href='".$link_address."'>Proceed to the next phase of the importation of data to the system</a></strong></br>";
}
else
{
echo "Error";
}
}
$zip = new ZipArchive;
$res = $zip->open($new_file_name);
if ($res === TRUE) {
$zip->extractTo($random_digit.'/');
$zip->close();
echo 'extraction successful';
} else {
echo 'extraction error';
}
是不是文件夹的模式阻止了提取?据我所知,没有语法错误.
Is it the mode of the folder which prevents extraction? As far as I can see, there is no syntax error.
推荐答案
try
$res = $zip->open($path)
当您将文件移动到 $path
后,您需要对位于 $path
As you have moved the file to $path
you then need to operate on the file at $path
这篇关于上传 Zip 文件并解压缩 Zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文