-4

I have a file("abc.csv") that is stored in the local system (for example: /var/a). I need to download the file when I hit a link in a Drupal site.

closed as unclear what you're asking by leymannx, Pierre.Vriens, mradcliffe, Kevin, kenorb Nov 8 '18 at 16:59

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

Drupal comes with options to define where the website media/files are stored. You can find it under Configuration > Media > File system (/admin/config/media/file-system).

You can assign a folder on the local system/server that serves as a Public files folder, and another folder that serves as a Private files folder.

Public files can be accessed by anonymous users (if they know the link), but Private files can't be downloaded even if you know the link to them if you don't have the appropriate user role that has access to the file (through Drupal Permissions, and of course if your server setup is properly secured).

Both options are tightly connected with the server permissions configuration. It's very important to configure your Drupal installation with secure server user folders and files ownership and permissions. If you have a "leaky" configuration your website can be hacked easily. Read more about folders and files permissions: Securing file permissions and ownership.

That is why it isn't a good idea to allow your Drupal website to link to just any file on the server/local system, and instead Drupal gives you one location to store all of the files you might need to display/link on your website.

It is possible to configure your Drupal installation to use the /var/a folder to store the Public files, but it requires expert server administration knowledge to make it work and make it secure.

Usually the Public files folder is held in the location: /sites/default/files (this is relative to the Drupal root installation folder, it is inside the Drupal folder).

If you upload a file to a Drupal Field and you don't define any custom options, or if you directly upload your files to that location you can link to the file with this path:

/sites/default/files/abc.csv

The full link would be:

<a href="/sites/default/files/abc.csv">Download my File</a>

Drupal keeps a record of files uploaded through Files API, and you can use Views to create lists of files, that display file names, links to download, and even other file information. That is a very handy way to automatically create links to files, if you have a lot of them.

  • i have to download the file when we give the "url" ? is it possible to create a custom module for getting the file and download it . – RAHUL SURENDRAN Oct 29 '18 at 4:51
  • The file isn't downloaded when you create the link. It is only when you click on the link on Drupal website that the file is downloaded. Or do you mean something different? Do you want to import the files from a local folder into Drupal? There are modules that can do that. You'll probably have to copy the files from your local folder into Drupal, and then use the Import interface so that Drupal can download and store those files in its files folder automatically. – prkos Oct 29 '18 at 10:19
  • what i mean that there is a URL when ever we search the URL it get the file from our local folder and download. That i want it. – RAHUL SURENDRAN Oct 29 '18 at 11:03
  • What do you mean "search the URL"? The file will always be in the same location, unless you move it or delete it. – prkos Oct 29 '18 at 11:04
  • consider there is a file in "/var/a/exp.csv" location when i search a url "localhost/transgenic/download" i have to download the file "exp.csv" .That means when search happen it goes to the specified location and get the file from there then it download to specified destination folder. – RAHUL SURENDRAN Oct 29 '18 at 11:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.