Jump to content

Download link replacing slashes in path with underscores


sac0o01

Recommended Posts

So I am trying to download an image created with my php script.  I use the following for the download:

 

<?php
session_start();
$filename = $_SESSION['imgOut'];

header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$filename );

?>

 

The file downloads however instead of downloading  "example.jpg" from the /temp folder , it downloads "temp_example.jpg"  which of course is an empty file.

 

I am sure I am approaching this the wrong way, any suggestions?

I see that now...so now I have to figure out how to call the image up.  If I echo $filename it returns the correct path  i.e.  temp/example.jpg

 

How do I go about downloading the image?  Right now I just tell users to right click and save but would like to have the download link or button.

As for the actual file data, you need to quite literally echo the contents into the browser after you've sent the content-type header:

 

echo file_get_contents($filename);

Looking at the name of your session varibale ("imgOut"), is application/octet-stream really the right content-type to use here?

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.