Welcome to Geeklog, Anonymous Friday, April 26 2024 @ 09:44 pm EDT

Geeklog Forums

error downloading pdf document


comas

Anonymous
angry
hey all, I have tried to use a php code for downloading a pdf document but gives this error
Cannot modify header information - headers already sent by (output started at /home/ceso/get_file.php:1) in /home/ceso/get_file.php on line 36

this is my getfile

<?php
ob_start() ;
// Make sure an ID was passed
if(isset($_GET['id'])) {
// Get the ID
$id = intval($_GET['id']);

// Make sure the ID is in fact a valid ID
if($id <= 0) {
die('The ID is invalid!'Wink;
}
else {
// Connect to the database
$dbLink = new mysqli('localhost', 'root', ' ', 'test'Wink;
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}

// Fetch the file information
$query = "
SELECT mime, name, size, data
FROM upload
WHERE id = {$id}";
$result = $dbLink->query($query);

if($result) {
// Make sure the result is valid
if($result->num_rows == 1) {
// Get the row
$row = mysqli_fetch_assoc($result);

// Print headers
header("Content-Type: ". $row['mime']);
header("Content-Length: ". $row['size']);
header("Content-Disposition: attachment; filename=". $row['name']);

// Print data
echo $row['data'];
}
else {
echo 'Error! No image exists with that ID.';
}

// Free the mysqli resources
@mysqli_free_result($result);
}
else {
echo "Error! Query failed:
Text Formatted Code
{$dbLink->error}
";
}
@mysqli_close($dbLink);
}
}
else {
echo 'Error! No ID was passed.';
}
ob_end_flush();
?>

 Quote

All times are EDT. The time is now 09:44 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content