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
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.

 

 

Link to comment
Share on other sites

I wanted to unzip one file to that location, then the images are to be renamed, and then resized, then moved and the original images + zip file is deleted. Then the same happens with the next file. But it doesnt work

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.