Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 11th Sep 2012, 12:08 PM   #1
Warrior Member
 
Join Date: 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default
I need a code to download images not to view them
Share on: 
fb share twitter share gplus share more share

I have images in my site, I want to download images when someone go to its link by clicking download link instead of viewing them using firefox, can any one help me to do that?
fakhris is offline  
Unread 11th Sep 2012, 12:20 PM   #2
Warrior Member
 
Join Date: 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: I need a code to download images not to view them
Share on: 
fb share twitter share gplus share more share

Any one please :-(

fakhris is offline  
Unread 11th Sep 2012, 12:48 PM   #3
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: I need a code to download images not to view them
Share on: 
fb share twitter share gplus share more share

Bumping your own thread after just 12 minutes? Great way to introduce yourself! :rolleyes:


Brandon Tanner is offline  
Unread 11th Sep 2012, 08:05 PM   #4
Warrior Member
 
Join Date: 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: I need a code to download images not to view them
Share on: 
fb share twitter share gplus share more share

First, setup your file field so that it saves into a separate directory. This will make it so that you will only force certain files to download and not affect the rest of the files on your Drupal site. Visit Administer -> Content management -> Content types (admin/content/types). Click "Manage fields" on the type that you want files to be forced to be downloaded. Add or edit a file field, under the "Path settings" fieldset, set a path for your files to be uploaded.
Now files uploaded to that field will be saved in a separate folder under your sites files directory.

FTP to your site and create a file named .htaccess in your files directory. Usually this will be sites/default/files/[name of the subdirectory from step 1]. In that file put the following lines:
<FilesMatch "\.(?i:doc|odf|pdf|rtf|txt)$">
Header set Content-Disposition attachment
</FilesMatch>
This particular example will force files with doc, odf, pdf, rtf, or txt to download instead of being shown in the browser.

Upload a few files and (using the "Generic files" display setting), the files will be downloaded when the user clicks on the link.
You may need to load mod_headers in Apache2 for this to work.
Assuming you have root access it can be done as follows:
# a2enmod headers
# /etc/init.d/apache2 reload
websamtron is offline  
Closed Thread


Bookmarks

Tags
code, download, images, view


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 11:50 AM.