I am using a php script to download files listed in a node. The files and the download script are located in ../sites/default/files. The php script (download.php) is as follows:

$file = $_GET['file']; 
header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$file.";");
header("Content-Length: ".filesize($file));
readfile($file);
exit;

In the ../sites/default/files directory there is an .htaccess file:

SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
<Files download.php>
SetHandler None
</Files>
Options None
Options +FollowSymLinks

On the Drupal node, I have a link that looks like this (first instance has a space between the .php? and file=):

<a href="sites/default/files/download.php? file=abj20080306.pdf"><b>Sharing a passion for baseball</b></a> by Stephanie Storm. [145 KB]
or
<a href="sites/default/files/download.php?file=abj20080306.pdf"><b>Sharing a passion for baseball</b></a> by Stephanie Storm. [145 KB]

When I was running Drupal 5.16, the script would execute fine and force a download of the file. (I don't want the file to open, but rather to be downloaded.) Now, with Drupal 6.11 the first instance of the link above results in an attempt to download the 'download.php' file. The second instance of the link results in an Internal Server Error (500).

Is there something different between Drupal 5.16 and 6.11 that would cause this behavior?

Thanks for the help.

Comments

cog.rusty’s picture

There is no important difference between 5.x and 6.x, but that doesn't matter anyway because you are accessing directly your own script file and not Drupal.

The first line in the small .htaccess file that you mentioned is specifically intended to prevent scripts to run (by setting the handler to a nonsense string), in case someone manages to upload a script, since it is an uploads directory,

PaulWood’s picture

Thanks for your reply.

As you suggest, the Drupal version shouldn't make any difference. So, I figured my problem was possibly due to the .htaccess file - however, the file is the same on my 6.x installation as it was on my 5.x installation. So, after some more looking around, I found that the attributes for the files folder in the 5.x installation was 755 whereas it was 777 for the 6.x installation. I set it back to 775 on 6.x. Still no help. After a while (and a few logins and logouts, cache clearing, etc.) things started working OK. So, I'm guessing the attribute setting of 777 was too open. Now, my download.php script runs fine.

Maybe this info will be helpful to someone else experiencing a similar problem.