PHP Read Zip Package

Source: Internet
Author: User
Tags ziparchive

$filename = $this->upload->data (' file_name '); Get the folder (here is the CI framework to get the file name after uploading the file)

$file _root = ' canddata/'. $time. ' /'. $filename;//Determine the directory of the zip package you uploaded

$zip = new ziparchive;//Create an Ziparchive object

$res = $zip->open ($file _root);//Open zip

Read zip

if ($res = = = TRUE) {

$zip->extractto ("./canddata/". $time. " /". Time ());//unzip the ZIP package to the specified directory

$zip->close ();

$dirs = "./canddata/". $time. " /". Time ()." /cand_picture/cands ";//Open the ZIP package after the folder below the file

$file = $this->wenjian ($dirs);//recursively queries the files under the folder (if the ZIP package is a single file, you do not need to traverse the folder, only the corresponding files can be processed)

Processing of the corresponding file

}

Traversing files
Public Function Wenjian ($dir)
{
$files = Array ();
if (@ $handle = Opendir ($dir)) {//note here to add an @, otherwise there will be warning error:)
while (($file = Readdir ($handle))!== false) {
if ($file! = ":" && $file! = ".") {//exclude root directory;
if (Is_dir ($dir. " /". $file)) {//If it is a subfolder, recursively
$files [$file] = My_dir ($dir. " /". $file);
} else {//otherwise the name of the file is stored in an array;
$files [] = $file;
}

}
}
Closedir ($handle);
return $files;
}
}

$tmp = $myfile [' Tmp_name '];
$path = "./images/". $myfile [' name '];
if (!move_uploaded_file ($tmp, $path)) {
Die (' upload failed ');
}

PHP Read Zip Package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.