Skip to main content

Joomla! 2.5 / Apache: File Downloads, docx etc.

I let my users upload files and link to them in their articles. As I want to force them to download the files directly (and don't want them to view it in the browser), I am using a file called download.php which I include in the URLs.

Thus, instead of "/myfolder/myfiles/myfile.pdf" the href attribute of the link will be like "download.php?filename=/myfolder/myfiles/myfile.pdf".

In download.php I declare headers and do some things about the filename. It was always working fine for pdf or doc files, but there seemed to be something wrong with the "new" file formats of Office (docx, ppsx etc.) - if a user clicked on that file, it would be downloaded, but could not be opened (the message said something like "cannot read file"). A comparison of the original file and the downloaded file showed no difference except for one character which was not even visible. Fun fact: OpenOffice could open the file without any problems... Lots of pages suggested to check the MIME type configuration of apache in /etc/mime.types, but the docx formats were already there.

I did a lot of research and came across a post on http://php.net/manual/de/function.header.php by eonrglez at gmail dot com.

I included all the header information suggested in this post (except for the file size), from Pragma to Content-Transfer-Encoding, and voilĂ  - it works.

Comments

Popular posts from this blog

Joomla! 2.5: Multiple views, one model

Here goes MVC again: I was a bit confused that every time I created a second or third view for a component, I had to create a separate model for it. Did not make sense to me - I had the necessary algorithms in the model for the first view, did I really need to do copy & paste? I hate it! Redundancy, redundancy, redundancy. That case occurred in my current project - I created user profiles and needed an "edit" view. The data is the same, but I need to have the data in editable text fields instead of fixed labels, and maybe some other buttons here and there...  Well, some time later I realized that I just did not quite understand what Joomla! acutally means by "view".  And that there is something called "layout". Long story short: If you have a model that provides all necessary information and you just want to have a different presentation of it, just add a new .php file to your views/<yourviewname>/tmpl folder - let's call it "layo

Eureka! Intel N 7260 Issue Appears To Be Solved

For a while now I've been having annoying trouble with my wireless adapter (Intel N 7260 - yes, I know it is known to cause trouble...). Not only did it not connect properly, it broke the wifi and the internet connection of the router in a way that no other device in the network could access the internet any more. I might just have discovered another possible cause: And guess what, Windows took me there. I know, right? So, this is what I did (I am on Win 10 right now): - It did not connect properly, as usual (for me this only happens when at home, where I am using a Speedport W 504V router) - so I ran Windows "troubleshooting" (right-click on the wifi icon in the task bar to get there) - It told me that there was an issue with a network protocol missing on my machine (which is rather ridiculous) - BUT at the bottom of the window it offered me a link to detailed information about the issue, which took me to a quite detailed troubleshooting report - This report lists

Joomla! 2.5: Menu Items

Some time ago, I started to create my own components. Everything was working fine, but there was one thing that bugged me (even though it is not really necessary... it just looked strange): When I create a link to my component, I always ended up with something like this in my menu manager: Similar thing for the menu item type: I felt like I somehow missed something, but the tutorials did not say anything about it. After playing around for a little while, I found out that the solution actually is pretty simple: The site > views > viewname > tmpl > default.xml file specifies these texts. Joomla! will look for these keys in the language files. Thus, you just need to add some entries to the language files and voila - everything looks nice and clean, just like this: Step-By-Step: Let's assume you already created the default.xml file with contents similar to these: <?xml version="1.0" encoding="utf-8"?> <metadata>