Intro: It was quite disappointing to realize that an amazing CMS like Drupal failed to have a rich download system. I was expecting a rich downloads section with categories, download counts, rating, etc. The script that answered it all was “pafiledb“. This article explains how to integrate pafiledb into Drupal as if it were a drupal module in a very easy manner. This is a must read for anyone using Drupal.
View a demo of pafiledb.
Installing pafiledb:
pafiledb has been successfully setup. For now, do not modify much. Just login to your pafiledb admin panel and create two categories and add a file.
Now we need to modify pafiledb a bit in order to work with drupal. The template style needs to be changed to removed the headers & unwanted content. I’ve created a custom template which you could install:
Now we need to mod drupal to implement pafiledb into it.
<?php if ( isset($_GET["fileid"]) ) { $pafile_params = "?act=view&id=" . $_GET["fileid"]; } elseif( isset($_GET["admin"]) ) { $pafile_params = "?act=login"; } ?> <iframe src="downloads/index.php<?php echo $pafile_params; ?>" name="frame1" scrolling="auto" frameborder="no" align="center" height = "500" width = "100%"> </iframe>
You will realize that pafiledb appears embedded within an iframe in the page you created. Read on to learn how to make your download system more powerful & integrated.
Q1) How to link to a file’s download page directly so that the user doesn’t have to go through the trouble of browsing through categories.
- Go to the download page for the file. (e.g /downloads/index.php?act=view&id=1 ) As you can see the “id” of the file is 1 in the url. Therefore, in the drupal page which displays the pafiledb, you can pass on the same id as a paramater using &fileid=1 at the end of the url. This will directly display the download page of the file in the iframe.
Q2) How do I make sure my visitors are not able to access the download page (/download/index.php) outside the drupal interface.
- To make sure, your downloads page is always inside your drupal theme as an iframe, we need to make the following changes:-
<SCRIPT LANGUAGE='javascript'> //this script makes sure that pafiledb is not loaded outside the downloads page iframe on drupal try { if (top == self) { top.location.href='../index.php?q=downloads'; } } catch(er) { } </SCRIPT>
Q3) How to administer my pafiledb? (This addition was made lately so please update the code in your static page before trying this out)
- To administer your pafiledb, visit yoursite/index.php?q=downloads&admin to login. After logging in, if you want a full page view of your admin panel, visit yoursite/downloads/admin.php
I hope this article was helpful. If you need any more help.. feel free to contact me!
Hi,
Thanks much for providing this writeup on making Drupal user friendly for file downloads! We had implemented a convoluted way to achieve the same but now am convinced I will use your scheme. The one question that I’ve for you is with regards to using the access control information from Drupal in deciding what files to serve for the download,i.e. we want certain users to be privy to only certain files to download, how can you achieve this? Since the database is served as an iframe, it seems to me there isn’t a good way to achieve what I’ve described but will await your guidance nevertheless.
Thanks & Cheers
/tesh
Hi tesh,
If you are looking for a way to restrict certain file downloads only to people with certain permissions, then you will have to try using one of the drupal php snippets and mod pafiledb itself. Will require quite a bit of php knowledge. I’m afraid there’s no easy way to do such a thing in a simplified manner. I’ve not really checked pafiledb, but I guess you can restrict files to registered users & a lot more here & there.. see it’s administration panel.
And if you are looking for a way in which you want to link to a file download page directly but within your drupal theme, then read question number 2. I hope this helps you enough…
Cheers
Dayson,
Thanks much for your pointer, I will take a look at the pafiledb internals first before I decide which way to go.
Cheers
/tesh
i dont think this works for drupal 6
Sorry, I’m not sure about that as I haven’t tried drupal 6.
H!
It works with Drupal 6
Thank you for this mods (I moded olate download to Drupal)
Hi , after creating a static page called downloads, the frame displays page not found ? where am I missing ? thanks..
Does the url of the frame actually exist?? Have you tried calling the actual page inside the frame directly in your browser?
It has been fixed. please remove the above comment.
Sorry for the inconvenience caused.
Thanks.