Jump to content

Allowing download of file from file field.


MuchDev
 Share

Recommended Posts

I am trying to have the ability to have a link on my navigation download a pdf catalog. I have a field named "file" that I use for these types of instances, but after just testing it I am now realizing that I may have an .htaccess issue. Is there  simple rule that would allow me to output a file download link by just using $page->file->url?

When I try and generate a link I get a propper path to the exact asset folder but then the link causes a 403. Should I approach a file download a different way then this?
 

Link to comment
Share on other sites

K after going in and increasing all of my memory limits in my php ini I am back in business. Looks like having my core memory limit at the default 128M was too low, so I went and bumped it to 256. I have a deecent server, should I go and bump this even higher, like 512+?

  • Like 1
Link to comment
Share on other sites

I am trying to have the ability to have a link on my navigation download a pdf catalog. I have a field named "file" that I use for these types of instances, but after just testing it I am now realizing that I may have an .htaccess issue. Is there  simple rule that would allow me to output a file download link by just using $page->file->url?

When I try and generate a link I get a propper path to the exact asset folder but then the link causes a 403. Should I approach a file download a different way then this?

The 403 means there's something wrong with your .htaccess -file or you are trying to access the asset-folder itself (and not an actual file inside there). Could you show us the link and/or code?

K after going in and increasing all of my memory limits in my php ini I am back in business. Looks like having my core memory limit at the default 128M was too low, so I went and bumped it to 256. I have a deecent server, should I go and bump this even higher, like 512+?

This shouldn't have anything to do with the 403 you were getting. 128M is perfectly fine for basic web page -stuff. There might be some serious design errors in your code if you are hitting the memory limit, I'm afraid :( If you could tell us a bit more - paste actual code and so on - we could help more. How large are the catalogs you are uploading?

  • Like 1
Link to comment
Share on other sites

So in the end my issue seemed to be in the processwire backend. I was trying to keep a simple file link of the companies’ current pdf catalog on the navigation at the top of the screen. I just wanted the client to be able to continue to release their catalogs in the format that they are use to. I have a template at the root of my page structure that contains global settings like logos and widgets. Inside of this template I have a file field that holds a downloadable file (a pdf). My issue was when I tried to upload the file it would show complete on the form, and then when one would try and click the link to the file there would be an error, and I would get a 403. The code that I used to generate the link was basically just this:

<a href="<?php echo $page->file->url;?>">Link to the thing</a>

The path that it generated was the correct path inside of my asset folder with the propper link, but as it was a bad file I was getting an error.

The PDF was about 52mb. When I increased my memory limit processwire then was completing the upload of the file, and the download links would then work. As to why this was the case I am unsure, but as the code for my site is pretty basic I am fairly certain I was just having a memory issue.  At this time I was also having some other issues with pro cache failing that seemed to be fixed when I switched over from fcgi to cgi processing. 

Link to comment
Share on other sites

If it is a memory issue it really has nothing to do with PW but PHP :-)

Forgive my ignorance:D

Thanks! The two processwire links I've read which is what got me through the issue. I'll read into those top 3 tonight. Youre a star!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...