Jump to content

PHP header download problem


UnsuitableBadger

Recommended Posts

I'm trying to do image downloads through the php header tags.

I pass a filename through to my download.php file and it should download but it keeps saving an html file instead of the image. I'm also using Joomla.

 

the images are in components/com_c/files/original/

this code is in [sitename]/components/com_c/views/account/download.php

<?php
// Define the path to file
$file = "components/$option/files/original/".$_REQUEST['file'];

if(!file)
{
     // File doesn't exist, output error
     die('file not found');
}
else
{
     // Set headers
     header("Cache-Control: public");
     header("Content-Description: File Transfer");
     header("Content-Disposition: attachment; filename=$file");
     header("Content-Type: image/jpg");
     header("Content-Transfer-Encoding: binary");
    
     // Read the file from disk
     readfile($file);
}
?>

 

it returns a file "sites_cara_components_com_c_files_original_0000000006.jpg" which is filled with html (presumably the html of the joomla that loads when it goes to the download.php)

 

Anyway know how I can make this work?

Link to comment
https://forums.phpfreaks.com/topic/184362-php-header-download-problem/
Share on other sites

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.