Jump to content

Multiple File Download


ddgrim

Recommended Posts

Hi,

I am trying to create a page where passing an ID of a file will allow multiple file downloads.

but only the first file is being downloaded, for example "file.php?code=1,2,3,4" will only download file 1

 

Any help would be much appreciated.

 

 

<?php 
$ItemID = $_GET['code'];
$FilesID = explode(",", $ItemID);
include('db.php');
foreach($FilesID as $ItemID){
$sql = "SELECT COUNT(*) FROM items WHERE ItemID = ".$ItemID.";";
$result = mysql_result(mysql_query($sql), 0);
if($result == 1){
	$sql = "SELECT ItemFileType, ItemName, Path, FileSize FROM items WHERE ItemID = ".$ItemID.";";
	$result = mysql_query($sql);
	$FileType = mysql_result($result, 0, 'ItemFileType');
	$ItemName = mysql_result($result, 0, 'ItemName');
	$Location = mysql_result($result, 0, 'Path');
	$FileSize = mysql_result($result, 0, 'FileSize');
	header("Content-Description: File Transfer", true); 
	header('Content-Disposition:attachment; filename='.$ItemName.'.'.$FileType.'', true);
	header('Content-Length: '.$FileSize.'', true); 
	readfile($Location.'/'.$ItemID.'.'.$FileType);

}
}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/193646-multiple-file-download/
Share on other sites

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.