Forum

Thread tagged as: Question, Configuration

File Downloads URL displayed

Hello,

I've been browsing the documentation and I'm having some trouble trying to set up file downloads the way I need them.

The website I'm developing does not need downloadable files to be "secure", as they're openly available to any visitor for download, such as a pdf file for a monthly calendar.

What is happening is that when a file is uploaded through either a perch content field of type="file" and then assigned to a bucket to keep things organized OR using markitup or an editor plugin like redactor, the output I see on the website is "/cms/resources/calendars/filename.pdf".

What I don't want is the file path to be displayed publicly. I'd like something like "/downloads.php?file=filename.pdf" to be displayed on the webpage and the address bar of the browser. Just something that will not give away the file path of the document.

The closest I've seen to something like this was in this section of the documentation: https://docs.grabaperch.com/docs/resources/buckets/

I'm not using the members app, so I'm not sure if the section that describes secure downloads has anything that applies to what I'd like to do.

I'm generally just confused as to how this needs to be setup.

  1. Would the "web path" be what is publicly displayed as the file path in the browser or is this only the path to a script?
  2. Would I even need a script to accomplish what I'd like to do?
  3. If I do need a script, are there any examples in the documentation I can reference?

Any guidance would be greatly appreciated.

Thank you, Joshua

Joshua Rodriguez

Joshua Rodriguez 2 points

  • 6 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

The documentation you have linked to is the way to do what you are asking.

Hi Rachel,

Yes, I've tried following the sample in the linked documentation, but I must be missing something.

I'm running xampp on a Windows 7 system, and trying to test locally to make sure I understand how it works before uploading to the live site and configuring the file path for the live server.

Here's what I have in my buckets.php config file for local testing:


<?php return array( 'calendars-2016' => array ( 'web_path' => '/calendars', 'file_path' => 'C:\xampp\htdocs\ihmsite\perch\resources\calendars-2016' ), ); ?>

When I upload a file and inspect the link displayed in the browser, I see:


<a href="/calendars/January2016.pdf" title="January Calendar for 2016"><i class=" fa fa-fw fa-download"></i> January 2016</a>

Then when I click on the link, I get an "Object Not Found" 404 error message in the browser.

Any ideas?

Thank you

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not sure what you're trying to achieve. What's the URL when you get a 404, and what should it be? What's preventing you correcting the link?

Hi Drew,

The URL I get is: https://ihms.dev/calendars/January2016.pdf

Basically, whenever I upload a file, whether through a file field or the markitup editor, its placed in a resource bucket, and the path displayed in the address bar or in the link itself is:

/cms/resources/calendars-2016/January2016.pdf

What I want to do is NOT display the direct path to these files. Instead of the URL displaying like above, I would like it to be displayed as:

/calendars/January-2016.pdf

...for both the address bar and the link itself within the page's content as in content & links added using the markitup editor.

The code in my buckets.php file from my earlier posts, seem to be making this change. What I'm wondering is if I still need a script to retrieve the file, should this work without a script, or would another solution be better for this (eg. htaccess)?

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you want the access to only go through a script then you need to locate the bucket outside of the web root.