[英]Inspect file in zip archive without extracting
I wrote a short code, which opens up a Zip File and searches for a file called "index.html". 我写了一个简短的代码,它打开一个Zip文件并搜索一个名为“ index.html”的文件。 Now I want to open the file and perform several actions. 现在,我想打开文件并执行几个操作。 - Search for links. -搜索链接。 - Search for clicktags. -搜索clicktag。
Please keep in mind, that this is done while the user is uploading his file. 请记住,这是在用户上传文件时完成的。 I dont want to extract is somewhere on the server. 我不想提取在服务器上的某个位置。
Is there a good method to achieve this? 有没有一个好的方法可以做到这一点? Regards 问候
$zip = new ZipArchive();
$zip -> open($filepath);
//Assign filescount to variable
$this ->adFileCount = $zip -> numFiles;
//Scan all files and find index.html
if($zip ->getFromName("index.html") == true)
{
//specific action done with index.html
}
Read the contents of the file and do whatever you need to with it. 读取文件的内容,然后对文件进行任何操作。
$zip -> open($filepath);
for($floop = 0; $floop < $zip->numFiles; $floop++ ) {
$stat = $zip->statIndex($floop);
if (stripos($stat['name'],'index.html') !== false) {
$indexcontents = $zip->getFromIndex($floop);
//
// do whatever you need to do with the array
// named indexcontents that contains index.html
//
}
} // end of for loop through the files in the zipped file uploaded
$zip->close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.