how to force file download when click on link

Mobile
feeds
Welcome Login | Register

how to force file download when click on link
Reply Your Comments:
Click this button if you are interested in replying to this topic and leave your comments
Sent To Friend
CLick this button if you want to send this page to a friend.
Subsribe To Rss Feeds
Subscribe to RSS
CLick this button if you want to subscribe to this RSS Feed. You can use your browsers feeds burners if you have mozilla or internet explorer 7 or higher and keep up with updates.
  Forums Index
      » PHP Forums
        » » how to force file download when click on link
how to force file download when click on link
Post Description: how to force file download when click on link PHP
Post Tags:
This Post Has Been Viewed 53 Times Since Tue Dec 23, 2008 2:34 pm Author wallpaperama with 1 replies
Next Post »» how to install pear cache_lite sytem on php
how to force file download when click on link
Advertise On This Page




often when i go to google.com and seach for images, sometimes, i find some pictures from blogger.com and when i click on the See full size image link, i get a popup windows to download the file instead of taking me to the the location where the file is:
20081223_6909_blogger-logo.jpg

you can try it yourself: go to

http://images.google.com/images?gbv=2&hl=en&q=site%3Ablogger.com+blogger+logo&btnG=Search+Images

well, i often wondered how they do that? i would like to know how they do that so i can do it on my website too.

ok, so im going to show you an example. i will make a short tutorial so you can also understand how they do it. however, one thing is required. and that is for you to have PHP. if you dont have PHP on your wesite, then this wont work. i dont know how to do this on microsoft windows server. im using a linux server with apache and php. so here we go.

step1. the first step is to create a directory where we can put our php file. so create a directory in your website and name it: test

step2. now we are going to create a file called image.php - open your text editor. im using a windows xp computer to write this tutorial, so ill be using notepad.

step3. copy and paste the code below into a blank notepad:

image.php
<?
# PATH TO THE IMAGE FILE IN YOUR WEBSITE
$file_name = 'wallpaperama.gif';
# USE THE HEADER() FUNCTION TO TELL THE BROWSER ON THE USERS THAT THIS IS AN ATTACHEMENT FILE TO FORCE TO DOWNLOAD
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
?>


step4. after you have copy and paste the code above, save the file as image.php

step5. now get any .gif image file you want and put it in our test directory and change the name of the file to wallpaperama.gif

step 6. now we are going to create a simple file to link to our image.php file. so copy and paste the following code to a new blank notepad:

index.php
<h1>Wallpaperama Image Tutorial</h1><hr />
<p><a href="image.php">Click on this link to download wallpaperama.gif</a></p>
<p>When you click on the the link above, you should get a little popup window asking you to download the image file instead of viewing it. now if you just want to view the file, then click on the following link:</p>
<p><a href="wallpaperama.gif">Click on this link to see wallpaperama.gif</a></p>
<p>This is just a simple script, however, once you understand the concept here, you can make it so that even if you click on the wallpaperama.gif, you can still force the user to download the file instead of vieiwing. for example. if the referer is not coming from your website, force the user to download the file, but if they are coming from your site, then allow them to view the image file fom their browser. another way you can use this is to count how many times people are downloading this file. using mysql database you can keep a track of how many donwloads and from where.</p>
<p align="center">Script by Wallpaperama.com</p>


step 7. once you have copy and save the code above, save the file as index.php

step 8. now upload the directory test to your PHP website and the three files:
image.php
index.php
wallpaperama.gif


step 6. now go to your website with your browser and open the test directory: example:
http://www.yoursite.com/test/index.php and see it in action.

hope this helps


searched by: image force download blogger.com HTTP response header



Leave Your Comments

Your Name
Your Email Address (Will Not Be Published)
Notify Me When Someone Replies to this Page
(An email will be sent to you when someone replies to your comments)
Your Comments
Include A Picture with your comments
Share
| More
Share this page by putting this URL in your comments to other websites like myspace, Facebook, Twitter friendster, Hi5, Groups, Boards, Forum or others. Just Copy and Paste this Code
URL:
To embed this topic, just copy the code from the "Embed" box. Once you've copied the code, just paste it into your website or blog to embed it.
Embed:
BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums
BBCODE:
Subscribe Feeds
Webmasters - Exchange Links With Us. Add related websites to this topic
Add Link:
Links Related to : how to force file download when click on link

Comments and replies About how to force file download when click on link
:: 1 :: Reply #99003 Reply By reift On Wed Apr 01, 2009 7:33 pm
reift:
01-6909-lb2-logo.gif
interesting. but i have been looking for an answer to a question that i just can not find. sometimes, when i messing around trying to improve seo, i screw something up and my links want to downlaod insted of just take you to the page. what causes this?
leapbrowser search engine.