troubleshooting Question

Header/readfile does not work when trying to display image outside of website root

Avatar of kgp43
kgp43Flag for Denmark asked on
8 Comments1 Solution1000 ViewsLast Modified:

I'm using this code to open an image saved outside of web root (home/kenneth/uploads/...)
It works fine in both IE and FF, but it does not work in Chrome - it just keep loading.

# Set headers
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=".$file['original_filename']);
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($absolute_path));


# Read the file from disk
$file['download_path'] = "http://".$file['hostname']."/download.php?token=".$token;

<img style="margin: 15px; max-width: 870px" src="<?php echo $file['download_path']; ?>" alt="<?php echo $file['original_filename']; ?>" />
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros