简体   繁体   中英

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". Now I want to open the file and perform several actions. - Search for links. - Search for clicktags.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM