13, February 2012

help on download script - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  Miscellaneous scripts or snippets (Moderator: Olaf)
Topic: help on download script
« previous next »
Pages: [1] Print

Author Topic: help on download script  (Read 1523 times)
I crack Photoshop!
*
Posts: 3
22 credits
Members referred : 0


« on: Oct 05, 2007, 07:15:42 pm »

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! 
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Oct 05, 2007, 10:42:27 pm »

whats your download code?


Last blog : A new Wordpress theme for our blog
I crack Photoshop!
*
Posts: 3
22 credits
Members referred : 0


« Reply #2 on: Oct 05, 2007, 11:12:06 pm »

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;
}

?>
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Oct 05, 2007, 11:15:25 pm »

you're sure that the path is fine?
dou you have white space in the begin of the script?

try error reporting...


Last blog : A new Wordpress theme for our blog
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5778
46265 credits
Members referred : 3



« Reply #4 on: Oct 05, 2007, 11:20:19 pm »

The problem is this :

if (isset($download)) {


$download is not seted anywhere.

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
I crack Photoshop!
*
Posts: 3
22 credits
Members referred : 0


« Reply #5 on: Oct 06, 2007, 12:02:42 am »

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 !  Smiley

thanks olaf, nicolas, much appreciated.

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5778
46265 credits
Members referred : 3



« Reply #6 on: Oct 06, 2007, 11:33:13 am »

You are welcome Smiley

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)) )?>

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7189
Tags : download files upload files Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  Miscellaneous scripts or snippets (Moderator: Olaf)
Topic: help on download script
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Feb 13, 2012, 04:19:58 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.