I needed to upload/download and play mp3 files on my site so I made a music module, it's still a bit buggy but overal it works good, I used the getid3 project to enable reading id3v2 tags, it disabled rewriting tags, because it was returning just to many errors at this time. Apart from storing the id3v2 info in the file, it's also stored in the db in a seperate table. Anyway i've been using it for some time now on my site and it's doing what it's supposed to except for the download feature. I just noticed a few days ago, that when a user is not logged in some files can be downloaded and some can't and return a '500 Internal Server Error'. Here's the code I use in for the download hook:
switch (arg(1)) {
case "download":
$node = node_load(array("nid" => arg(2)));
header("Expires: ". gmdate("D, d M Y H:i:s") ." GMT");
header("Content-Type: audio/mpeg");
header("Content-Length: ". $node->filesize);
header("Content-Disposition: attachment; filename=" .$node->filename);
readfile(variable_get("music_files_dir", "music_files/") ."musicfile_$node->nid.mp3");
db_query("UPDATE {music} SET downloads = downloads + 1 WHERE nid = $node->nid");
break;
}
I suspect it probably has something to do with drupal caching these pages, because while logged in there's no problem at all.
If anyone can has any idea how I should handle this or how I can disable the caching for these pages, please let me know.
Comments
hate to say it, but....
There are already modules that do this! Look at flexinode, it has getid3 implemented and uses the Drupal fileapi to hande up and downloads. Could you not better improve that flexinode system, rather then start from scratch and create yet another module?
[Ber | Drupal Services webschuur.com]
I know!
Yes I just found out, but I wrote this a few months ago, so ...
But I'll see if I can make a contribution to the module.
--- MultipleX
www.hambastegimeli.com
Don't click this link if you don't know Farsi!