Does anyone know how to add a download link for an image file? You generally give the address of a zip but i want to download an image. How will you add a "click to download" link.
How to add a download link?
Whith an image is generally: "Right click and Save as... to download image'.
The browser automatically detects image filetypes and shows thm instead of downloading. What you can do is generate a zip file automatically (whith PHP) whith the image/s inside.
Sorry, I dont know any other solution...
The browser automatically detects image filetypes and shows thm instead of downloading. What you can do is generate a zip file automatically (whith PHP) whith the image/s inside.
Sorry, I dont know any other solution...
| kevinalle wrote: |
| Whith an image is generally: "Right click and Save as... to download image'.
The browser automatically detects image filetypes and shows thm instead of downloading. What you can do is generate a zip file automatically (whith PHP) whith the image/s inside. Sorry, I dont know any other solution... |
Well, I wanted something like a "download now" link. I want to host some of my game scripts and photoshop images on my website for download. I thought a download link would be nice. Moreover, I would like to convert my site to be viewable in mobile phones through wap. Right click is not possible on wap phones I believe.
mobile phones directly download ALL images, and saves them. There you dont have any problem.
For computers, I suggest using PHP to dinamically generate a zip file whit the image/s. It is very easy and effective
For computers, I suggest using PHP to dinamically generate a zip file whit the image/s. It is very easy and effective
You have to send certain headers so that it ends up as downloaded and not displayed. Use php to make a redirect to the image, but with something changed. I can't be sure what, because I haven't seen it it a while, years even.
http://us2.php.net/manual/en/function.header.php
Read the part about "Content-Disposition".
http://us2.php.net/manual/en/function.header.php
Read the part about "Content-Disposition".
wow, I didn't know about that...
It's really cool.
Thanks for the tip!
It's really cool.
Thanks for the tip!
I would suggest just telling the user to right-click and save image as.
| Code: |
|
<?php $dir = ""; if (file_exists($dir)) { header('Pragma: amytextexeptno-cache', true); header('Content-type: application/force-download'); header('Content-Transfer-Encoding: Binary'); header('Content-length: ' . filesize($dir)); header('Content-disposition: attachment; filename=' . basename($dir)); readfile($dir); } |
make the dir variable the file you want to download the file should be the webserver path, i'm not too sure if this works with urls but might[/code]
like this
<a href=¡°¡±><img src=""></a>
<a href=¡°¡±><img src=""></a>
| seawolfxp wrote: |
| like this
<a href=¡°¡±><img src=""></a> |
That will just show the image in the browser. The easiest way is to instruct surfers to download by right-clicking and "Save Target As.." I havent' tried the one using PHP. I guess that would be useful for large images.
| ftasyo wrote: | ||
That will just show the image in the browser. The easiest way is to instruct surfers to download by right-clicking and "Save Target As.." I havent' tried the one using PHP. I guess that would be useful for large images. |
The "save target as" function you talk about is only in ie, well its not in firefox
The only thing i do is as is suggested above to give a link directly to the image and for the user to save that image..
Hope this helps
Ryan
The easiest way to do this is in PHP. Instead of linking to the image file, link to a PHP page that serves the image file to your browser. The PHP page will set the Content-Disposition item in its HTTP response to download, and the user will be forced to download the image rather than display it. Here's some example code:
Create a PHP page with this and only this in it, then link to it instead of directly linking to the image file. If your image isn't a .jpg, check [url="http://www.utoronto.ca/webdocs/HTMLdocs/Book/Book-3ed/appb/mimetype.html"]here[/url] for a list of MIME Content types.
| Code: |
|
<?php header('Content-disposition: attachment; filename=FILENAME.jpg'); header('Content-type: image/jpeg'); readfile('FILENAME.jpg'); ?> |
Create a PHP page with this and only this in it, then link to it instead of directly linking to the image file. If your image isn't a .jpg, check [url="http://www.utoronto.ca/webdocs/HTMLdocs/Book/Book-3ed/appb/mimetype.html"]here[/url] for a list of MIME Content types.
