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
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.
Link to comment
Share on other sites

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? :(
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.