5, September 2008

help on download script - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ 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 791 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 Visit through proxy . 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: 6307
38662 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 : Is your website is down? Know before your visitors do!
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: 6307
38662 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 : Is your website is down? Know before your visitors do!
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8037
41179 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 Visit through proxy

Last blog : MIA - Where Nick and Tim
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: 8037
41179 credits
Members referred : 3



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

You are welcome Smiley

BTW using isset() Visit through proxy 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 Visit through proxy

Last blog : MIA - Where Nick and Tim
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....

Topic sponsors:
Get a permanent link here for $1.99!


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?
Sep 05, 2008, 07:48:51 AM





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: 36.290
Total Topics: 7.476
Total Members: 3.897
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: FlorianHofmann

17 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 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.