Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] jak dodac "filtr" dla nazwy pliku w tym skrypcie, chcialbym dodac do skryptu filtr na podstawie nazwy pliku
gariz
post 5.08.2008, 11:21:33
Post #1





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 7.06.2007

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


mam taki skrypt
  1. <?php
  2. function returnimages($dirname=".") {
  3. $pattern="(.jpg$)|(.png$)|(.jpeg$)|(.gif$)"; //valid image extensions
  4. $files = array();
  5. $curimage=0;
  6. if($handle = opendir($dirname)) {
  7. while(false !== ($file = readdir($handle))){
  8. if(eregi($pattern, $file)){ //if this file is a valid image
  9. //Output it as a JavaScript array element
  10. echo 'galleryarray['.$curimage.']="'.$file .'";';
  11. $curimage++;
  12. }
  13. }
  14.  
  15. closedir($handle);
  16. }
  17. return($files);
  18. }
  19.  
  20. echo 'var galleryarray=new Array();'; //Define array in JavaScript
  21. returnimages() //Output the array elements containing the image file names
  22. ?>


i chcialbym zeby nie byly wczytywane wszystkie pliki graficzne ale tylko takie ktore maja w nazwie min_
Go to the top of the page
+Quote Post
jarmiar
post 5.08.2008, 11:30:30
Post #2





Grupa: Zarejestrowani
Postów: 616
Pomógł: 12
Dołączył: 16.07.2006
Skąd: : getCity ( );

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


może tak

  1. <?php
  2. $pattern="(min_(.*).jpg$)|(min_(.*).png$)|(min_(.*).jpeg$)|(min_(.*).gif$)";
  3. ?>


--------------------
Jeśli my czegoś nie zrobimy, zrobią to za nas inni
Go to the top of the page
+Quote Post
wrzasq
post 5.08.2008, 11:33:05
Post #3





Grupa: Zarejestrowani
Postów: 206
Pomógł: 18
Dołączył: 6.03.2006
Skąd: Szczecin

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


@jarmiar: nie, nie tak.

linijka 3:
  1. <?php
  2. $pattern = '^.*min_.*.(gif|png|jpg|jpeg)$'; // jezeli chcesz, aby pliki zaczynaly sie od "min_" a nie tylko "mialy w nazwie", to zamiast '^.* wpisz tylko '^
  3. ?>


linijka 8:
  1. <?php
  2. if( preg_match($pattern, $file) ){
  3. ?>


Ten post edytował wrzasq 5.08.2008, 11:34:50


--------------------
Go to the top of the page
+Quote Post
gariz
post 5.08.2008, 11:34:40
Post #4





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 7.06.2007

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


o kurde to az takie proste bylo - a ja kombinowalem tak pod gorke ze masakra

ale dziala sposób jarmiar'a

dzieki wielkie!!!

Ten post edytował gariz 5.08.2008, 11:35:48
Go to the top of the page
+Quote Post
rzymek01
post 5.08.2008, 11:46:55
Post #5





Grupa: Zarejestrowani
Postów: 592
Pomógł: 62
Dołączył: 3.08.2006

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


ja proponuje funkcję glob smile.gif


--------------------
:]
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 Wersja Lo-Fi Aktualny czas: 27.06.2025 - 08:10