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?
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6274
38470 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?
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:
Posts: 6274
38470 credits Members referred : 374
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
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:
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> </p>\n<p> </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
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6274
38470 credits Members referred : 374