I need a code to download images not to view them

3 replies
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?
#code #download #images #view
  • Profile picture of the author fakhris
    Any one please :-(
    {{ DiscussionBoard.errors[6964646].message }}
    • Profile picture of the author Brandon Tanner
      Bumping your own thread after just 12 minutes? Great way to introduce yourself! :rolleyes:
      Signature

      {{ DiscussionBoard.errors[6964769].message }}
      • Profile picture of the author websamtron
        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
        {{ DiscussionBoard.errors[6967037].message }}

Trending Topics