Jump to content

File download not working


Nolongerused3921

Recommended Posts

Well I'm trying to get file output through a control script to work, so that I can make sure a user has permissions to view that file... But its just not working - its seeing the file size, its outputing the information, but its just not showing up... Its always an improper image and I'm wondering why....

My code:
[code=php:0]
<?php
ob_start();
include_once('functions.inc.php');
include_once("header.inc.php");
if(isset($_GET['id'])) {
$id = $_GET['id'];
$sql = "SELECT * FROM files WHERE id='$id'";

$result = $mysql->query($sql,"get_file");
$file = $mysql->fetch_row('get_file');

header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Transfer-Encoding: binary");
header("Content-length: $file[size]");
header("Content-type: $file[mime]");
header("Content-Disposition: attachment; filename=$file[name]");
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
set_time_limit(0);

$filename = $exact_dir."/uploaded/".$file[id]."_".$file[name];
$filename = realpath($filename);
@readfile($filename);


exit;
}
ob_flush();
?>
[/code]

The file exists and all that as well, heres what size, mime, and name are:
Size: 59300
Mime: image/pjpeg
Name: 1832-b.jpg

What could be going wrong here?
Link to comment
https://forums.phpfreaks.com/topic/34044-file-download-not-working/
Share on other sites

[code]
  Array
(
    [id] => 7
    [name] => 1832-b.jpg
    [sort_id] => 19
    [user_id] => 1
    [size] => 59300
    [mime] => image/pjpeg
    [date] => 1168582898
)


[/code]

Weird huh? :( I've even tried taking out the includes, ob_start, and sql stuff and hard code the headers/path myself... Still showing a broken image.
Well this kind of sucks... I took out everything and completely rewrote it by hand:
[code=php:0]
$filename = $exact_dir."/uploaded/7_1832-b.jpg";
$filename = realpath($filename);
// header("Pragma: public");
// header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// header("Cache-Control: private",false);
// header("Content-Transfer-Encoding: binary");
header("Content-length:".filesize($filename));
header("Content-type: image/pjpeg");
header("Content-Disposition: attachment; filename=7_1832-b.jpg");
// header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
// set_time_limit(0);


@readfile($filename);
[/code]

And it works... But I can't do this on my actual site, I [b]need[/b] to include the header and functions files, but they have header()s in them... Any ideas? :(
I've already figured it out, its the fact that I'm including functions.inc.php and headers.inc.php, but I [b]need[/b] these two files included... They just call forth sessions, cookies, and I think a header or two... Is there a way to get this to work without unincluding them?

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.