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
https://forums.phpfreaks.com/topic/138368-solved-problem-in-download-http-headers/
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.

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.