This is my scenario:
- I upload a zip file
- Check each file in zip file
- If file != image, then move file to destination
- if file == image, resize image and move to destination
I googled around and seen different solutions, but none where one can process files before saving them at the final destination.
This is the function I got so far:
// Extract zip file and return files in an array.
private function processZip() {
$zip = new ZipArchive;
$tmp_dir = FB_PLUGIN_DIR.'tmp/';
// Extract files to tmp dir
if ($zip->open($this->file['tmp_name']) === TRUE) {
//Check if temp dir exists. If not, create one.
if (!is_dir($tmp_dir)) {
mkdir($tmp_dir, 0700);
}
$zip->extractTo($tmp_dir);
$zip->close();
/* Process extracted files */
foreach(glob($tmp_dir.'*.*') as $filename) {
// Somehow get MIME type here without using 'finfo' and 'mime_content_type'
// I haven't installed PEAR and 'mime_content_type' is decapricated.
}
return '1'; // success
} else {
return "0"; // fail
}
}
I’m not sure if I’m going in the right direction here. Somehow I think I should be able to process the files while in the “ZIP loop”.
Is there a way I can read the files in the ZIP file, determin the MIME type and then process file?
I found this example: http://www.java-samples.com/showtutorial.php?tutorialid=985
I think it’s close to what I need. But not sure what to modify.
Decouple your processes. Extract everything from the ZIP file first, then scan the files for image files and process them.
It’s a simpler process, and can be more easily decomposed for dealing with larger zipfiles.