Jump to content

[SOLVED] problem in Download HTTP headers


BloodyMind

Recommended Posts

I've got a problem in this http headers, maybe in the filename or path I've tried alot but no joy

this script is to get the filename from the database and set the path to it so it gets downloaded.

 

getfile.php:

<?php

if(is_numeric($_GET['fid'])){
$dirs = new Directories($db['host'],$db['username'],$db['password'],$db['name']);

$fileId = $_GET['fid'];

$rows = $dirs->getFile($fileId);
if (!is_array($rows)) {
	echo $row;
}
foreach ($rows as $files){
	$file = urldecode($files['file_name']);

}
$file = urldecode($file);

$file_size = filesize(realpath($file));

$file = urlencode(basename($file));
$file = basename($file);




//	$final_file = urlencode(USER_UPLOADS . "/" .$file);
$final_file = $file;
if (!is_file($final_file)) {
	echo $final_file;
}
header("Content-length: {$file_size}");
header("Content-disposition: attachment; filename= '$final_file'");
header("Content-type: image/jpg");
header("Content-Description: Project File");

}

?>

 

What this script does?

It downloads a file with the same name but, 0 bytes :(

 

any kind of help will be so appreciated

Thank you

Link to comment
Share on other sites

Your code doesn't redirect the browser to the file, it just tells it that the file will be named blah, it's a blah type file, then after the headers are sent, it doesn't send any data.

 

You need to open the file in question with fopen(), then echo() the contents of the file out to the browser.

 

OR

 

You need to actually redirect the browser to the actual file.

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.