16, March 2010

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 1269 times)
I crack Photoshop!
*
Posts: 3
22 credits
Members referred : 0


« on: Oct 05, 2007, 08: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: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Oct 05, 2007, 11: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 06, 2007, 12:12:06 am »

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: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Oct 06, 2007, 12:15:25 am »

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: 5659
45587 credits
Members referred : 3



« Reply #4 on: Oct 06, 2007, 12:20:19 am »

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, 01: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: 5659
45587 credits
Members referred : 3



« Reply #6 on: Oct 06, 2007, 12:33:13 pm »

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?
Mar 16, 2010, 11:48:56 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!


Forum Statistics
Total Posts: 44.173
Total Topics: 8.616
Total Members: 8.211
Tutorials : 58
Resources : 929
Designs : 360
Latest Member: makebelieve

47 Guests, 4 Users online :

14 users online today:



Readers

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