Sublime directory Surf the web anonymous Pagerank Monitor


help on download script

gawa
Fri 5 October 2007, 07:15 pm GMT +0200
hi all, newbie here.... first, thanks Olaf for sharing this upload/download script which i am tinkering at www.alphabet-ny.com/clientLogin/page.php . the uploading part runs OK but i am lost why it can't run the download part. it will show an error message on the browser if it has an error right? but i only see a blank page and nothing is downloading. hope somebody can point me where to find solution for this.  btw, i tested the scripts to a different server and uploading/downloading files were OK.

thanks in advance! 

olaf
Fri 5 October 2007, 10:42 pm GMT +0200
whats your download code?

gawa
Fri 5 October 2007, 11:12 pm GMT +0200
here is the download.php Olaf, i didnt really changed much from the original code.

<?php
$folder = $_SERVER['DOCUMENT_ROOT']."/clientLogin/files/";

if (isset($download)) {
    $fullPath = $folder.$_POST['file_in_folder'];

    if ($fd = fopen ($fullPath, "r")) {
        $fsize = filesize($fullPath);
        $path_parts = pathinfo($fullPath);
        $ext = strtolower($path_parts["extension"]);
        switch ($ext) {
            case "jpg":
            header("Content-type: image/jpg");
            header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use "attachment;" for forcing download rather than just viewing on page - as jpgs and gifs will be displayed if attachment isn't indicated.
            break;
            case "zip":
            header("Content-type: application/zip");
            header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
            break;
    case "pdf":
            header("Content-type: application/pdf");
            header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
            break;
           
        }
        header("Content-length: $fsize");
        header("Cache-control: private");
        while(!feof($fd)) {
            $buffer = fread($fd, 2048);
            echo $buffer;
        }
    }
    fclose ($fd);
    exit;
}

?>

olaf
Fri 5 October 2007, 11:15 pm GMT +0200
you're sure that the path is fine?
dou you have white space in the begin of the script?

try error reporting...

Nikolas
Fri 5 October 2007, 11:20 pm GMT +0200
The problem is this :

if (isset($download)) {


$download is not seted anywhere.

gawa
Sat 6 October 2007, 12:02 am GMT +0200
took the cue from Nicolas and changed:

if (isset($download)) ===>>  if (isset($_POST['file_in_folder']))

i am not sure if my coding is proper but its running OK !  :)

thanks olaf, nicolas, much appreciated.


Nikolas
Sat 6 October 2007, 11:33 am GMT +0200
You are welcome :)

BTW using isset() to determine if the form is posted is not the best way, because if the user post an empty form isset will return true.

You can better use

if ( !empty($_POST['file_in_folder)) )?>

Archive for SMF v1.00 by N.P. Valid XHTML 1.0 Transitional