$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