Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Skrypt pobierania php
Forum PHP.pl > Forum > Przedszkole
alfemix
Witam!
Jest to pierwszy mój post na tym forum. Mam pewne pytanie do tej społeczności.
Czy ma ktoś taki skrypt, który daje listę plików z podanymi rozszerzeniami (pdf,jpg,bmp itp) i gdy naciśniemy na nazwę pliku na tej liście pobiera nam się ten plik. Prosiłbym o jakieś linki, skrypty, ja nic nie napiszę bo dopiero zaczynam. Pardzo proszę o pomoc, gdyż taki skrypt jest mi bardzo potrzebny.
Mam oto taki skrypt



CODE
<?php
header("Content-type: application/octet-stream");

header("Content-Length: " . filesize('nazwa.pdf'));

header('Content-Disposition: attachment; filename="nazwa.pdf"');

readfile('nazwa.pdf');
?>


ale to muszę robić ręcznie, a chodzi mi o to żeby tylko do danego folderu dać pliki do pobrania i wyświetlić listę, a użytkownik z tej listy wybiera coś naciska i m u się pobiera automatycznie.
kamilos809
Hej, mogę Ci o tyle ułatwić, że dam Ci kod, który niedawono sam znalazłem i edytowałem. Niestety tylko na archiwa(.zip) i na jedno rozszerzenie działa, ale to już początek. Pobawisz się tym trochę a zrobisz smile.gif

  1. <?
  2. global $PHP_SELF, $op;
  3. $dir = opendir("Kopie_zapasowe");
  4.  
  5. $a = 0;
  6. $b = 0;
  7.  
  8. echo '<table width="99%" align="center">';
  9.  
  10. while($file = readdir($dir)) {
  11. $len = strlen($file);
  12. $file = substr($file, 0, $len);
  13. $name[0] = $file;
  14. $opt[] = $name[0].'<===>'.$file.'.zip';
  15. }
  16.  
  17. asort($opt);
  18. foreach($opt AS $index => $file) {
  19. $fil = explode('<===>', $file);
  20. $opt2[] = $fil[1];
  21. }
  22.  
  23. foreach($opt2 AS $index => $file) {
  24.  
  25. if($b>=2) {
  26.  
  27. if($a==0) {
  28. echo '<tr>';
  29. }
  30.  
  31. $len = strlen($file);
  32. $file = substr($file, 0, $len-8);
  33.  
  34. $name[0] = $file;
  35.  
  36. if($op==$file) $wp1 = '<b>'; else $wp1 = '';
  37.  
  38. echo '<td class="uni_01">'.$wp1.'&middot;'.$name[0].'<a href="?op=kopia_zapasowa&cmd=usun&plik='.$file.'">[DEL]</a> <a href="Kopie_zapasowe/'.$file.'.zip">[POBIERZ]</a></td>';
  39.  
  40. $a++;
  41.  
  42. if($a==1) {
  43. echo '</tr>';
  44. $a = 0;
  45. }
  46. }
  47.  
  48. $b++;
  49.  
  50. }
  51.  
  52. echo '</table>';
  53. ?>
alfemix
Dziękuję za szybką reakcję smile.gif
wgrałem na serwer i niestety:

CODE

Warning: opendir(Kopie_zapasowe) [function.opendir]: failed to open dir: No such file or directory in /home/blastcra/public_html/test/index.php on line 3

Warning: readdir(): supplied argument is not a valid Directory resource in /home/blastcra/public_html/test/index.php on line 10

Warning: asort() expects parameter 1 to be array, null given in /home/blastcra/public_html/test/index.php on line 17

Warning: Invalid argument supplied for foreach() in /home/blastcra/public_html/test/index.php on line 18

Warning: Invalid argument supplied for foreach() in /home/blastcra/public_html/test/index.php on line 23
Rysh
Nie może otworzyć Ci folderu /test/ prawdopodobnie nie ma takiego folderu lub nie ma uprawnień do niego (chmod).
alfemix
Teraz nic nie wyświetla sad.gif nawet jak ma pliki do znalezienia


Znalazłem coś takiego:
CODE
<?PHP
function getDir($extList)
{
if(!($fd = opendir($dir))){
return false;
}
$arr = explode(";", $extList);
foreach($arr as $key => $file){
$arr[$key] = trim($file);
}
$contents = "<PRE>";
while (($file = readdir($fd)) !== false){
if(($file == "..") || ($file == ".")){
continue;
}
$ext = substr($file, strlen($file) - 3, 3);
$ext = strtolower($ext);
if(in_array($ext, $arr)){
$contents .= "<A HREF=\"$dir$file\">$file</A>";
$contents .= "\n";
}
}
$contents .= "</PRE>";
closedir($fd);
return($contents);
}
?>
<HTML>
<HEAD></HEAD>
<BODY>
<?PHP print(getDir("./images/", "jpg"));?>
</BODY>
</HTML>




Nie działa sad.gif

Poprawiłem działa smile.gif Dziękuję za pomoc! Temat do zamknięcia
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.