Jump to content

Uploading -> Extracting multiple zip files


insidus

Recommended Posts

Scenario:

I've got a form, which you use to ad multiple items of stock and for each item of stock, you can upload a zip file, which will contain 1 - "unlimited" amount of images. I need to be able to unzip the first file, then rename the images, then store them in a folder unique to that stock item, then do the same for every other stock item.

 

So far, i've managed the uploading form, and can upload 1 zip file for each stock item, save it, and it is viewable on the server. However, i can't get the extracting to work.

 

$files_uploaded = array();
for ($i = 0; $i < sizeof($_FILES['files']['name']); $i++) {
		$file = $i;
		$target_path = "image_processing/" . $file . '.zip';
		move_uploaded_file($_FILES['files']['tmp_name'][$i], $target_path);
		array_push($files_uploaded, $target_path);
}

for($i = 0; $i < sizeof($files_uploaded); $i++)
{
	echo $files_uploaded[$i] . " ";
	$zip = new ZipArchive();

	$res = $zip->open($files_uploaded[$i]);
	if ($res === TRUE)
	{
		$zip->extractTo('image_processing/resizing/');
		$zip->close();
		echo " done ";
	}

	unset($zip);
}

 

This either seems to unzip all the files simultaneously, or just does the one, im not too sure. But it certainly doesn't do one file at a time.

 

Thanks for any help, its highly appreciated!

 

/insidus

Link to comment
https://forums.phpfreaks.com/topic/263912-uploading-extracting-multiple-zip-files/
Share on other sites

...then store them in a folder unique to that stock item...

 

 

$zip->extractTo('image_processing/resizing/');

 

I don't know what your "unique folder" naming convention is supposed to be but it should be implemented somewhere in that line of code...otherwise all your zips are being unzipped to that same folder.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.