Jump to content

Foreach stops executing after 1 loop


pocobueno1388

Recommended Posts

I have a program where the user can select multiple categories, then multiple cities. It should loop through each category, then download a file for each chosen city for that category.

 

<?php

if ($_POST['export']){

$categories = $_POST['categories'];
$cities = $_POST['cities'];

foreach ($categories AS $category){

	foreach ($cities AS $city){

		$keyword = new keyword(FALSE, $category, $city);
		$keyword->export();

		$file = ("keywords.csv");
		header ("Content-Type: application/octet-stream");
		header ("Accept-Ranges: bytes");
		header ("Content-Length: ".filesize($file));
		header ("Content-Disposition: attachment; filename=$category - $city");
		readfile($file);

	}
}		
}

?>

 

I'm pretty sure the loop isn't the problem. I think it's all the headers that are for someone reason stopping the execution. It will download the FIRST file, but then completely stops. It should automatically start multiple downloads.

 

I'm thinking it's something to do with one of the headers...like only one download can happen at once.

 

Any help would be greatly appreciated, Thanks!

Link to comment
Share on other sites

You can only output one set of headers and the corresponding file contents per HTTP request.

 

You can either dynamically produce a set of 'download links' on a page so that the visitor can click on each of them or you would need to zip the contents of all the files into a single download.

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.