File Download issue

Discussion in 'PHP' started by troinfo, Jan 7, 2008.

  1. #1
    Hello All and Happy New Year !!!

    I hope someone can help me with this download issue.

    I'm trying to change the download location link that the user sees when downloading files from there account. Basically to prevent them saving the link to file.

    I found this:

    http://richardlynch.blogspot.com/2006/06/php-downloads-content-disposition.html

    It seems to be exactly what I want.

    However, I get this message when I attempt to use it:

    Internal Server Error
    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, webmaster and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.


    As per the link above here is my code:

    Code for the .htaccess file:

    
    <Files dtest>
      ForceType application/x-httpd-php
    </Files>
    
    Code (markup):
    The .htaccess file seems to be working as I can run a script without having the .php at the end of the file in the dir that the file is located in.

    Code for the dtest file:

    
    <?
    require 'pathinfo.php';
    $filename = $PATH_VARS['filename'];
    $filename = $_GET['filename'];
    $filename = basename($filename);
    if ($filename != 'test.txt') die("Did you really think I wouldn't add filename validation here?");
    $basename = '/download/tempdownload/';
    $fullname = "$basename$filename";
    $filesize = filesize($fullname);
    header("Content-length: $filesize");
    header("Content-type: application/octet-stream");
    readfile($fullname);
    ?>
    
    Code (markup):
    Code for the pathinfo.php

    
    <?
        //Consider a URL such as:
        //  http://example.com/scriptname/var1=val1/var2=val2/path/to/filename.xyz
        //Transform it into:
        //  $PATH = '/path/to/filename.xyz'
        //    $PATH_VARS['var1'] = 'val1';
        //    $PATH_VARS['var2'] = 'val2';
    
        $PATH = '';
        $parts = explode('/', $_SERVER['PATH_INFO']);
        foreach ($parts as $part){
            $pieces = explode('=', $part);
            switch(count($pieces)){
                case 1: /* tack it on as part of a pathname */
                    //Also ignore the leading '/' of PATH_INFO which turns into an empty '' from explode()
                    if ($pieces[0] !== '') $PATH .= "/" . $pieces[0];
                break;
                default: /* Set up something like $_GET only with $PATH_VARS */
                    $var = $pieces[0];
                    // value might have = within it...
                    unset($pieces[0]);
                    $val = implode('=', $pieces);
                    $PATH_VARS[$var] = $val;
                break;
            }
        }
    ?>
    
    Code (markup):
    I'm sure it is something stupid between the chair and the keyboard.
    Any help would be greatly appreciated.

    TIA,
    troinfo
     
    troinfo, Jan 7, 2008 IP
  2. lfhost

    lfhost Peon

    Messages:
    232
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Tells you what to do.
    If you are on a cpanel based server, login to your control panel and check your error_log section. It will tell you what it at fault more in detail.

    A 500 error can be a range of things from

    1, File/Folder Permissions (most commonly on CGI files)
    2, Incorrect settings in .htaccess or server disallows this.

    Where exactly is the .htaccess file used ? In the download directory ? Or? It looks imcomplete to me as you should set file extentions after the application/x-httpd-php i.e. application/x-httpd-php .zip .php .html .htm .avi etc etc (im not the best at Apache commands sorry)
     
    lfhost, Jan 8, 2008 IP
  3. troinfo

    troinfo Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The .htaccess file is in the tempdownload dir.

    I will check the logs and get back to you.

    Thanks,
    troinfo
     
    troinfo, Jan 8, 2008 IP