22, August 2008

easy upload and download need help! - 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  >  Easy PHP Upload (Moderator: Olaf)
Topic: easy upload and download need help!
« previous next »
Pages: 1 [2] Print

Author Topic: easy upload and download need help!  (Read 2327 times)
Metal slug addict
*
Posts: 19
118 credits
Members referred : 0


« Reply #20 on: Apr 24, 2007, 09:55:25 AM »

another thing is on my main file directory i have 2 user sub directories then on the user sub directories there are other directories.  Grin
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6300
38626 credits
Members referred : 374


It's time to use PHP5!


« Reply #21 on: Apr 24, 2007, 11:02:40 AM »

done! but its a blank page. ive named it ex.php. ive change the path2file to my needs but its blank

you need to have all code in the same page/script (and this is not html Smiley)


Last blog : Create custom backups from your website using cURL
Metal slug addict
*
Posts: 19
118 credits
Members referred : 0


« Reply #22 on: Apr 24, 2007, 11:28:15 AM »

this is the page still the first error and the drop down menu:


<?php
function select_files($dir, $label = "Directory", $select_name, $curr_val = "", $char_length = 30) {
    $teller = 0;
    if ($handle = opendir($dir)) {
        $mydir = ($label != "") ? "<label for=\"".$select_name."\">".$label."</label>\n" : "";
        $mydir .= "<select name=\"".$select_name."\">\n";
        $curr_val = (isset($_REQUEST[$select_name])) ? $_REQUEST[$select_name] : $curr_val;
        $mydir .= ($curr_val == "") ? "  <option value=\"\" selected>...\n" : "<option value=\"\">...\n";
        while (false !== ($file = readdir($handle))) {
            $files[] = $file;
        }
        closedir($handle);
        sort($files);
        foreach ($files as $val) {
            if (is_file($dir.$val)) { // show only real files (ver. 1.01)
                $mydir .= "    <option value=\"".$val."\"";
                $mydir .= ($val == $curr_val) ? " selected>" : ">";
                $mydir .= (strlen($val) > $char_length) ? substr($val, 0, $char_length)."...\n" : $val."\n";
                $teller++;   
            }
        }
        $mydir .= "</select>";
    }
    if ($teller == 0) {
        $mydir = "No files!";
    } else {
        return $mydir;
    }
}

echo select_files("/var/www/html/files/");

if (!empty($_REQUEST['selectfoldername'])) {
$path = $_SERVER['DOCUMENT_ROOT']."/var/www/html/files/"; // play with the path if the document root does noet exist
$fullPath = $path.$_GET['selectfoldername'];

if ($fd = fopen ($fullPath, "r")) {
    $fsize = filesize($fullPath);
    $path_parts = pathinfo($fullPath);
    $ext = strtolower($path_parts["extension"]);
    switch ($ext) {
        case "pdf":
        header("Content-type: application/pdf"); // add here more headers for diff. extensions
        header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachement' to force a download
        break;
        default;
        header("Content-type: application/octet-stream");
        header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
    }
    header("Content-length: $fsize");
    header("Cache-control: private"); //use this to open files directly
    while(!feof($fd)) {
        $buffer = fread($fd, 2048);
        echo $buffer;
    }
}
fclose ($fd);
exit;
}

first part is the first code, the the second part is the second, im i on the right track? Cool
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6300
38626 credits
Members referred : 374


It's time to use PHP5!


« Reply #23 on: Apr 24, 2007, 11:41:23 AM »

do you have a link?

btw. did you more than copy pasting the code I suggested?


Last blog : Create custom backups from your website using cURL
Metal slug addict
*
Posts: 19
118 credits
Members referred : 0


« Reply #24 on: Apr 24, 2007, 12:01:57 PM »

the webpage link can only be seen locally. remember the recent earthquake. this cause some of our lines no able to be publish outside. sorry. wat do you mean paste more? i cannot understand.
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6300
38626 credits
Members referred : 374


It's time to use PHP5!


« Reply #25 on: Apr 24, 2007, 04:07:17 PM »

the webpage link can only be seen locally. remember the recent earthquake. this cause some of our lines no able to be publish outside. sorry. wat do you mean paste more? i cannot understand.

It looks to me that you just copy/past my code suggestion and didn't tried the code by yourself


Last blog : Create custom backups from your website using cURL
Metal slug addict
*
Posts: 19
118 credits
Members referred : 0


« Reply #26 on: Apr 25, 2007, 02:21:42 AM »

 Sad you're right i copy/paste the code. wat should i alter and revised on your code? i'll try to work around with it though. thanks
Metal slug addict
*
Posts: 19
118 credits
Members referred : 0


« Reply #27 on: Apr 25, 2007, 04:55:01 AM »

this is the error  Grin


Warning: fopen("/var/www/html/var/www/html/files/", "r") - No such file or directory in /var/www/html/olaf.php on line 131

Warning: fclose(): supplied argument is not a valid File-Handle resource in /var/www/html/olaf.php on line 151
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6300
38626 credits
Members referred : 374


It's time to use PHP5!


« Reply #28 on: Apr 25, 2007, 08:57:21 AM »

this is the error  Grin


Warning: fopen("/var/www/html/var/www/html/files/", "r") - No such file or directory in /var/www/html/olaf.php on line 131

Warning: fclose(): supplied argument is not a valid File-Handle resource in /var/www/html/olaf.php on line 151

this way it want work you need to learn php first...


Last blog : Create custom backups from your website using cURL
Metal slug addict
*
Posts: 19
118 credits
Members referred : 0


« Reply #29 on: Apr 26, 2007, 03:36:45 AM »

thats ok, im sad though. ill just have to find some other alternatives. thanks
Atari ST fan
*
Gender: Female
Posts: 7
46 credits
Members referred : 0


Let's code!


« Reply #30 on: Jun 14, 2007, 12:16:45 PM »

Hey Andoy, I think I've got your answer. I also had a major problem with the "easy upload php" script that was handling the download snippet.  I believe there was some fundamental instructions left out (something to do with the $select_name - I can trace the logic to here, but can't find where this is defined... and this is why I kept getting the error "Warning: Missing argument 3 for select_files() in /var/www/html/upload_class/directory.php on line 3"... because $select_name IS argument 3) - but not to worry here's how I managed to get the files to list for downloading... and actually download....

######   Place at top of PHP file which will display the downloadable files.

<?php
$folder = $DOCUMENT_ROOT."/yourImageFolder/"; // the folder which you want to list the files from

function select_files($dir) {
    global $PHP_SELF;
    $teller = 0;
    if ($handle = opendir($dir)) {
        $mydir = "<p><strong>Choose image to download from the list below...</strong></p>\n";
        $mydir .= "<form name=\"form1\" method=\"post\" action=\"thisDownloadsPage.php\">\n";  // change page to your download page...
        $mydir .= "  <select name=\"file_in_folder\" id=\"file_in_folder\">\n";
        $mydir .= "    <option value=\"\" selected>... </option>\n";
        while (false !== ($file = readdir($handle))) {
            $files[] = $file;
        }
        sort($files);
        foreach ($files as $val) {
            if ($val != "." && $val != "..") {
                $mydir .= "    <option value=\"".$val."\">";
                $mydir .= (strlen($val) > 30) ? substr($val, 0, 30)."...</option>\n" : $val."</option>\n";
                $teller++;     
            }
        }
        $mydir .= "  </select>";
        $mydir .= "<p><input type=\"submit\" class=\"submit\" name=\"download\" value=\"Download\"></p>";
        $mydir .= "</form>\n";
        closedir($handle);
    }
    if ($teller == 0) {
        echo "<p>&nbsp;</p>\n<p>&nbsp;</p>\n<p class=\"green\">(There are currently no files available for downloading.)</span>";      // this will display if the folder is empty
    } else {
        echo $mydir;
    }
}
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;
            default;
            header("Content-type: application/octet-stream");
            header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
        }
        header("Content-length: $fsize");
        header("Cache-control: private");
        while(!feof($fd)) {
            $buffer = fread($fd, 2048);
            echo $buffer;
        }
    }
    fclose ($fd);
    exit;
}         
?>


## Place in document where you want the list of documents to appear.

<?php echo select_files("yourImageFolder/"); ?></p> // replace yourImageFolder with your image folder name.

**************
I hope this helps you out Smiley
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6300
38626 credits
Members referred : 374


It's time to use PHP5!


« Reply #31 on: Jun 14, 2007, 12:30:08 PM »

must say my answer was a little rude  Embarrassed

anyway thanks for sharing this!


Last blog : Create custom backups from your website using cURL
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=6415
Tags : easy upload php Bookmark this thread : Digg Del.icio.us Dzone more....

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


Pages: 1 [2] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  Easy PHP Upload (Moderator: Olaf)
Topic: easy upload and download need help!
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Aug 22, 2008, 03:34:45 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.084
Total Topics: 7.439
Total Members: 3.807
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: marthawelch

37 Guests, 3 Users online :

16 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.