Tuesday, March 26, 2013

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.

Thursday, March 21, 2013

Joomla! 2.5: Finally - A Soulution For Applying Changes (Front End Editing)

This is about (front end) creating / editing an article.

I have been looking for a way to save (apply changes) in Joomla's front end for a really long time. What I needed was just a button which would let me save changes without redirecting somewhere else...

Recently I came across this page.

I applied all suggested changes to my page, and it works! On the downside you need to edit Joomla core files, and the changes made to them will probably be lost after the next update...

Tuesday, March 19, 2013

Joomla! 2.5: Another LDAP (?) Issue

This one was really driving me crazy. Really.

But we can't blame LDAP for that, at least I don't think so...


We have a LDAP authentication set up which is working really well. Except when a user enters a wrong password - then he just gets a blank page. The same is the case for articles with a user restriction (user need to be logged in to view the article) - again, just a blank page.

Turns out the blank page is not as blank as it seems - the source is there, including a nice error message. And a line somewhere in the head saying

html{display:none;}

A lot of research took me to this page, and I decided to try the following, out of some instinct:

"Comment out line 823 (or thereabouts) in:
libraries> joomla > html > html> behavior.php
$document->addStyleDeclaration('html { display:none }');
To comment out, just add 2 slashes "//" in front of the line."


Works like a charm. I am afraid the change will be undone by the next Joomla update, but I'll try to report a bug. In the meantime I hope this helps. Happy coding!

edit: Someone reported a bug on a similar problem, seems like version 2.5.9 will not have this line any more. See here.