Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]wyświetlanie zdjęc
Forum PHP.pl > Forum > Przedszkole
dave666
witam mam takie pytanie jak zrobic w tym skrypcie aby pokazywało tylko pliki jpg i png zapewne to banalnie proste ale dla takiego lamera jak ja to cos tudnego będę bardzo wdzieczny za pomoc
ps: do administratorów jezeli cos nie tak umiescilem prosze o pomoc gdzie i jak mam umescic post aby byl umieszczony zgodnie z regulaminem


  1. <?php
  2.  
  3.  $path = $_GET['path'];
  4. if(!isset($path))
  5. {
  6. $path = ".";
  7. }
  8.  
  9. if ($handle = opendir($path))
  10. {
  11. $curDir = substr($path, (strrpos(dirname($path."/."),"/")+1));
  12.  
  13.  while (false !== ($file = readdir($handle)))
  14. {
  15. if ($file != "." && $file != "..")
  16.  
  17.  {
  18.  
  19.  
  20. $fName = $file ;
  21. $file = $path.'/'.$file;
  22. print "<table width='320px' border='1' cellspacing='0' cellpadding='0' align='center' >";
  23.  if(is_file($file)) 
  24. {
  25.  $file_size = filesize($file);
  26.  $file_size = round($file_size /1024/1024 ,3);
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  print "<td width = '180' class='ramka2' ><font color=\"ffffff\">
  35.  <img src='".$file."' width=\"60px\" height=\"60px\"'><b>".$fName."</b></a>
  36.  </td>
  37.  <td class='ramka2' width = '60'>
  38.  <form action=\"usun.php\" method=post> 
  39. <table border=0>
  40. </tr>
  41. <tr><td> 
  42.  <td><font color=\"ffffff\">Zaznacz</td> <td><input type=\"checkbox\" name=\"plik2\" size=20 maxlength=100 value=\"$fName\"></td> 
  43. </tr></td>
  44.  
  45. <tr>
  46. <td colspan=2 align=center><input type=submit value=\"Usuń\">
  47. </td></tr>
  48. </table>
  49. </form></center></td></table>";
  50. }
  51.  
  52.  
  53. if(is_dir($file))
  54.  
  55. {
  56.  
  57. }
  58.  
  59. }
  60. }
  61. closedir($handle);
  62. }
  63.  ?>
chemik1982
Jedno z rozwiązań:

  1. <?php
  2.  
  3.  $path = $_GET['path'];
  4. if(!isset($path))
  5. {
  6. $path = ".";
  7. }
  8.  
  9. if ($handle = opendir($path))
  10. {
  11. $curDir = substr($path, (strrpos(dirname($path."/."),"/")+1));
  12.  
  13.  while (false !== ($file = readdir($handle)))
  14. {
  15. if ($file != "." && $file != "..")
  16.  
  17.  {
  18.  
  19.  
  20. $fName = $file ;
  21. $file = $path.'/'.$file;
  22. print "<table width='320px' border='1' cellspacing='0' cellpadding='0' align='center' >";
  23.  if(is_file($file)) 
  24. {
  25. $file_size = filesize($file);
  26. $file_size = round($file_size /1024/1024 ,3);
  27.  
  28. $tmp = explode('.',basename($file));
  29. $file_ext = $tmp[count($tmp)-1];
  30.  
  31. $extensions = array('png','jpg');
  32.  
  33. if(in_array($file_ext,$extensions)){
  34.  
  35.  print "<td width = '180' class='ramka2' ><font color=\"ffffff\">
  36.  <img src='".$file."' width=\"60px\" height=\"60px\"'><b>".$fName."</b></a>
  37.  </td>
  38.  <td class='ramka2' width = '60'>
  39.  <form action=\"usun.php\" method=post> 
  40. <table border=0>
  41. </tr>
  42. <tr><td> 
  43.  <td><font color=\"ffffff\">Zaznacz</td> <td><input type=\"checkbox\" name=\"plik2\" size=20 maxlength=100 value=\"$fName\"></td> 
  44. </tr></td>
  45.  
  46. <tr>
  47. <td colspan=2 align=center><input type=submit value=\"Usuń\">
  48. </td></tr>
  49. </table>
  50. </form></center></td></table>";
  51. }
  52. }
  53.  
  54.  
  55. if(is_dir($file))
  56.  
  57. {
  58.  
  59. }
  60.  
  61. }
  62. }
  63. closedir($handle);
  64. }
  65.  ?>
dave666
dziekuję wszystko pokazuje elegankc jednak są ludzie którzy pomagają smile.gif
DannyM
Jeszcze jedno. Moze prosciej dac tabele w
  1. <?php
  2. echo ' ';
  3. ?>
a nie bawic sie w łamianie \smile.gif
gox
ja bym to zrobil na mime_content_type()
mozna wiedziec co robi ta linia:
$curDir = substr($path, (strrpos(dirname($path.'/.'),'/')+1));
komp to kuma, ja nie bardzo..
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.