Original article: http://dayson.thewomo.com/2007/10/28/integrating-pafiledb-into-drupal/

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. View a demo of pafiledb. So lets get about installing & setting up pafiledb (I used v3.6) on your Drupal website.

Installing pafiledb:

  • Unzip the file you downloaded from the paFileDB homepage.
  • Open the "upload" folder, then open "includes" and then open the file "config.php". You will need to edit that file to reflect your MySQL server information. You will need to edit the server, username, password and the database name.
  • Make a folder in your drupal root directory called "downloads".
  • Open up the "upload" folder from the file you just unzipped. Copy everything, except for the "upgrade" folder from this folder into the "downloads" folder you just created.
  • Navigate to the "downloads/install/index.php" folder using your web browser and setup pafiledb with any settings you want.
  • Once you've done so, you will be prompted to delete the install folder and then you can easily view your pafiledb by browsing to your /downloads/index.php folder.

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:

  • Download the modded template of pafiledb by clicking here.
  • Extract the downloaded file and copy all the files from the extracted "templates" folder into the "downloads/skins/default/templates" folder. Make sure this replaces the files in the templates folder.

Now we need to mod drupal to implement pafiledb into it.

  • Create a static page say "Downloads" by using the Create Content >>> Page option in drupal.
  • Set the input format of the page to "PHP code"
  • Paste the code below in the Body of the new page

<?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>
  • Save the page & view it.

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:-

  • Open the file "downloads/index.php" in your text editor.
  • Paste the code below at the top of the file.

<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> 
  • Make sure to edit the "top.location.href" in the code above to the path of your drupal page which the user should be always directed to access the downloads page.

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!

- Dayson Pais
http://dayson.thewomo.com

Original article link: http://dayson.thewomo.com/2007/10/28/integrating-pafiledb-into-drupal/

Comments

dayson’s picture

Hi, there was a bug in viewing the admin panel of pafiledb which has now been fixed..
it has been updated in the above article as well as on http://dayson.thewomo.com/2007/10/28/integrating-pafiledb-into-drupal/

so do update the code edits.

Draven_Caine’s picture

* Paste the code below in the Body of the new page

if ( isset($_GET["fileid"]) )
{
    $pafile_params = "?act=view&id=" . $_GET["fileid"];
}
elseif( isset($_GET["admin"]) )
{
    $pafile_params = "?act=login";
}
echo $pafile_params; " name="frame1" scrolling="auto" frameborder="no" align="center" height = "500" width = "100%">

* Save the page & view it.

In this part of your write-up there is a slight issue. the iframe src="downloads/index.php is missing a / infront of the downloads.

Igbonine’s picture

Subscribing

domineaux’s picture

There are a series of youtube videos on how to hack sites by going through the PAFILEDB.

The support for the Pafiledb has always been very spotty as well.

I don't think this is a best alternative to just about anything... IMO, of course.

Also, I noticed ther pafiledb website is no longer up either.