[eluser]Mitchell[/eluser]
I'm trying to download and display an image stored in a directory above the web root--something I've done many times pre-CI (I've been experimenting with CI for a couple of weeks now). If I use an old pre-CI file located in the public_html directory, the image displays just fine.
View Code
Code:
<img src="/download_file.php">
download_file.php code
Code:
$file_name = 'pix.jpg';
$full_path = '/home/path/to/folder/file_name';
$file_size = filesize($full_path);
$file_type = 'image/jpeg';
if (file_exists($full_path))
{
$fp = fopen($full_path, 'rb');
header ("Content-Type: $file_type \n");
header ("Content-Length: $file_size \n");
fpassthru($fp);
exit();
}
But if I use the download helper force_download(), the image doesn't display, but rather the binary file is displayed.
View code:
Code:
$this->load->helper('download');
$name = 'photo.jpg';
$data = file_get_contents('/home/path/to/folder/pix.jpg);
force_download($name, $data);
After a few hours of experimenting with anything I could think of, I took the old code that was correctly displaying the image and simply moved it from the public_html folder to the CI application folder which is above the web root and changed the view code appropriately. Interestingly, once I moved the working code to the application folder, it no longer worked and also displayed the binary output instead of showing the image.
There is probably something really stupid that I'm doing, but I'll be darned if I can figure out what it is.
Oh, the directory stucture is as follows with system and application above the web root.
system
application
public_html
Mitchell