Welcome to Geeklog, Anonymous Sunday, July 21 2024 @ 07:21 am EDT

Geeklog Forums

Group file download permissions.

Status: offline


Forum User
Registered: 12/14/05
Posts: 21
Location:Iowa City, IA
Possibly useless to anyone but me, but I'll share.
Similar to file management plugin but much simpler, and stores the files outside the webroot (if you want to that is, it can go either way)

I came across the problem of distributing mp3s of songs to cover to band members, but being a RIAA fearing man the general public should not be able to access them. So I just slightly modified this random image script http://alistapart.com/d/randomizer/rotate.txt (I striped out all the credit when I was working on it to avoid nested comment problems.)

Text Formatted Code
$grouptrue = SEC_inGroup('Geeklog Group Name');
if ($grouptrue == 1){

        $folder = '/some/folder/out/of/web/root/with/mp3s/in/it/';

    $extList = array();     //any type of file you want to serve up
        $extList['mp3'] = 'audio/mpeg';
        $extList['zip'] = 'application/zip';

// You don't need to edit anything after this point.

// --------------------- END CONFIGURATION -----------------------

$img = null;

if (substr($folder,-1) != '/') {
        $folder = $folder.'/';

if (isset($_GET['song'])) {
        $imageInfo = pathinfo($_GET['song']);
        if (
            isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
        file_exists( $folder.$imageInfo['basename'] )
    ) {
                $img = $folder.$imageInfo['basename'];
} else {
        $fileList = array();
        $handle = opendir($folder);
        while ( false !== ( $file = readdir($handle) ) ) {
                $file_info = pathinfo($file);
                if (
                    isset( $extList[ strtolower( $file_info['extension'] ) ] )
                ) {
                        $fileList[] = $file;

        if (count($fileList) > 0) {
                $imageNumber = time() % count($fileList);
                $img = $folder.$fileList[$imageNumber];

if ($img!=null) {
        $imageInfo = pathinfo($img);
        $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
        header ($contentType);
} else {
        if ( function_exists('imagecreate') ) {
                header ("Content-type: image/png");
                $im = @imagecreate (100, 100)
                    or die ("Cannot initialize new GD image stream");
                $background_color = imagecolorallocate ($im, 255, 255, 255);
                $text_color = imagecolorallocate ($im, 0,0,0);
                imagestring ($im, 2, 5, 5,  "IMAGE ERROR", $text_color);
                imagepng ($im);
$display = COM_siteHeader('true','Band Members Only');
$display .= COM_startBlock('Unauthorized');
$display .=  '<p>Get the *censored* out of here!, If you\'re in the band log in, if that doesn\'t work, contact Grant at: <br><img src="http://www.grantgarvey.com/email/8cd16151b8838f8c6ea60de3e7c4736f" alt="Privacy"></p>';
$display .= COM_endBlock();
$display .= COM_siteFooter('true');
echo $display;

Then I used some Apache Mod_Rewrite Action to force the files to save as the .mp3 extension and not a php audio file Frown

#.htaccess file in webroot
RewriteEngine On
RewriteRule ^(.+)\.mp3$ protect/song.php?song=$1.mp3
#Rewrites anything.mp3 to the download script as the get variable 'song'.mp3

So in my case vinylband.net/rockthecasbah.mp3 will give you all a most unpleasant message and allow a band member to download Rock the Casbah by The Clash. And going through the script is the only way to get it from my webserver.

First, hopefully someone else can put this to use, as you can adapt it to any file type.
Second, can anyone tell me if there are any problems with this?

I know that it could be much shorter but the randomness might come in handy in the future.


All times are EDT. The time is now 07:21 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content