Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Skrypt pobierania php, Skrypt pobierania php ,który wyświetli listę pobierania z katalogu
alfemix
post
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 10.02.2015

Ostrzeżenie: (0%)
-----


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.
Go to the top of the page
+Quote Post
kamilos809
post
Post #2





Grupa: Zarejestrowani
Postów: 165
Pomógł: 3
Dołączył: 2.04.2010

Ostrzeżenie: (10%)
X----


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. ?>
Go to the top of the page
+Quote Post
alfemix
post
Post #3





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 10.02.2015

Ostrzeżenie: (0%)
-----


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
Go to the top of the page
+Quote Post
Rysh
post
Post #4





Grupa: Zarejestrowani
Postów: 821
Pomógł: 111
Dołączył: 11.09.2006
Skąd: Biała Podlaska

Ostrzeżenie: (0%)
-----


Nie może otworzyć Ci folderu /test/ prawdopodobnie nie ma takiego folderu lub nie ma uprawnień do niego (chmod).


--------------------
Go to the top of the page
+Quote Post
alfemix
post
Post #5





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 10.02.2015

Ostrzeżenie: (0%)
-----


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


Ten post edytował alfemix 10.02.2015, 19:53:08
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 08:42