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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.