php script to split download into chunk
Im writing PHP script for downloading files. I would like to split the
download into chunk lest say 1024 per chunk, can someone give me the code
for that. im storing my files in mysql database.
Here is my download script,
<?php
$company =$_GET['company'];
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
if($id <= 0)
{
die('The ID is invalid!');
}
else
{
$dbLink = new mysqli('localhost', 'sqldata', 'sqldata', 'balhaf');
if(mysqli_connect_errno())
{
die("MySQL connection failed: ". mysqli_connect_error());
}
$query = "SELECT mime, name, size, data FROM $company WHERE id = $id";
$result = $dbLink->query($query);
if($result)
{
if($result->num_rows == 1) {
$row = mysqli_fetch_assoc($result);
$size = $row['size'];
$filename = $row['name'];
$data = $row['data'];
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=".($filename));
header("Content-Length: ".($size));
echo $row['data'];
exit();
}
else
{
echo 'Error! No image exists with that ID.';
}
@mysqli_free_result($result);
}
else
{
echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
}
@mysqli_close($dbLink);
}
}
else
{
echo 'Error! No ID was passed.';
}
?>
No comments:
Post a Comment