Visualizzazione dei risultati da 1 a 9 su 9

Discussione: Aiuto per un "$filter"

  1. #1
    Utente di HTML.it L'avatar di pariri
    Registrato dal
    Jul 2003
    Messaggi
    1,470

    Aiuto per un "$filter"

    Ciao a tutti!

    in una pagina php ho questa riga:

    $filter = ".mp3" ;

    che mi va a leggere tutti i files che metto in "mp3" in una cartella, però mi servirebbe cambiarla per fare leggere anche un altro tipo di file! Come posso modificarla?

    Grazie del vostro aiuto!
    La vita è un percorso, goditi il viaggio.

  2. #2
    Utente di HTML.it L'avatar di carlo2002
    Registrato dal
    Jun 2002
    Messaggi
    2,746
    Non puoi cambiare solo quella riga, da qualche parte ci sarà una condizione concepita per verificare singolarmente l'unico valore di quella variabile.

    Quindi dovresti postare la parte di codice che utilizza quella variabile per poter capire come risolvere.

    Errare humanum est, perseverare ovest

  3. #3
    Utente di HTML.it L'avatar di pariri
    Registrato dal
    Jul 2003
    Messaggi
    1,470
    Eccoti il codice:

    codice:
    <?php
    
    // set this to a creator name
    $creator = " ";
    
    // search for mp3 files
    $filter = ".mp3";
    
    // path to the directory you want to scan
    // "./" = current directory
    $directory = "./mp3";
    
    // URL to files
    $url = "http://www.miosito.it/multimedia/";
    
    /////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    
    // read through the directory and filter files to an array
    @$d = dir($directory);
    if ($d)
    {
      while($entry = $d->read())
      {
        $ps = strpos(strtolower($entry), $filter);
        if (!($ps === false))
        {
    //////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
          // unset($output);
          // exec('stat -t ' . escapeshellarg($entry), $output);
          // print "<pre>";
          // print_r($output);
          // exit;
          // $output = explode(' ', $output[0]);
          // $items[$entry]['mtime'] = $output[10];
    //////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    
          //...Windows normal code - sorting by mtime
          // $items[$entry]['mtime'] = filemtime($entry);
    
          //...Linux/Unix code - sorting by mtime
          // There is an option in the "stat" command to return the MAC timestamps of a file in epoch time,
          // where Access/Modify/Change are given in format %X/%Y/%Z.
          // $items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
    
          //...Windows/Linux/Unix normal code - sorting by filename
          $items[$entry] = $entry;
        }
      }
      $d->close();
      // reverse sort - latest first
      // arsort($items);
      // normal sort - alphabetically by filename
      asort($items);
    }
    
    // xml header and opening tags
    header("content-type:text/xml;charset=utf-8");
    
    print <<<END
    <?xml version='1.0' encoding='utf-8'?>
    <playlist version='1' xmlns='http://xspf.org/ns/0/'>
      <title>Multimedia</title>
      <trackList>
    
    END;
    
    // loop through the array to build the track
    foreach($items as $key => $value)
    {
      $title = substr($key, 0, strlen($key) - 4);
      print <<<END
        <track>
          <creator>$creator</creator>
          <title>$title</title>
          <location>$url/$key</location>
        </track>
    
    END;
    }
    
    // closing tags
    print <<<END
      </trackList>
    </playlist>
    
    END;
    
    ?>
    Grazie!!
    La vita è un percorso, goditi il viaggio.

  4. #4
    Utente di HTML.it L'avatar di carlo2002
    Registrato dal
    Jun 2002
    Messaggi
    2,746
    Puoi trasformare la variabile $filter, che contiene l'estensione del file, in un array in cui metti le varie estensioni che ti interessano

    Codice PHP:
    // search for audio files
    $filter = array(".mp3",".wav",".aiff") ; 
    poi verifichi la presenza dell'estensione nell'array
    Codice PHP:
    // read through the directory and filter files to an array
    @$d dir($directory);
    if (
    $d)
    {
      while(
    $entry $d->read())
      {

        
    $ext strrchr(strtolower($entry),'.') ;

        if ( 
    in_array($ext$filter) ) 
        { 
    l'ho buttato giù così, prova se funziona
    Errare humanum est, perseverare ovest

  5. #5
    Utente di HTML.it L'avatar di pariri
    Registrato dal
    Jul 2003
    Messaggi
    1,470
    uhmmm... non funziona
    La vita è un percorso, goditi il viaggio.

  6. #6
    Utente di HTML.it L'avatar di carlo2002
    Registrato dal
    Jun 2002
    Messaggi
    2,746
    riposta il codice modificato
    Errare humanum est, perseverare ovest

  7. #7
    Utente di HTML.it L'avatar di pariri
    Registrato dal
    Jul 2003
    Messaggi
    1,470
    eccoti:

    codice:
    <?php
    
    // set this to a creator name
    $creator = " ";
    
    // search for audio files
    $filter = array(".mp3",".flv") ;
    
    // path to the directory you want to scan
    // "./" = current directory
    $directory = "./mp3";
    
    // URL to files
    $url = "http://www.miosito/mp3/";
    
    /////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    
    // read through the directory and filter files to an array
    @$d = dir($directory);
    if ($d)
    {
      while($entry = $d->read())
      {
    
        $ext = strrchr(strtolower($entry),'.') ;
    
        if ( in_array($ext, $filter) ) {
        {
    //////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
          // unset($output);
          // exec('stat -t ' . escapeshellarg($entry), $output);
          // print "<pre>";
          // print_r($output);
          // exit;
          // $output = explode(' ', $output[0]);
          // $items[$entry]['mtime'] = $output[10];
    //////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    
          //...Windows normal code - sorting by mtime
          // $items[$entry]['mtime'] = filemtime($entry);
    
          //...Linux/Unix code - sorting by mtime
          // There is an option in the "stat" command to return the MAC timestamps of a file in epoch time,
          // where Access/Modify/Change are given in format %X/%Y/%Z.
          // $items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
    
          //...Windows/Linux/Unix normal code - sorting by filename
          $items[$entry] = $entry;
        }
      }
      $d->close();
      // reverse sort - latest first
      // arsort($items);
      // normal sort - alphabetically by filename
      asort($items);
    }
    
    // xml header and opening tags
    header("content-type:text/xml;charset=utf-8");
    
    print <<<END
    <?xml version='1.0' encoding='utf-8'?>
    <playlist version='1' xmlns='http://xspf.org/ns/0/'>
      <title>Multimedia</title>
      <trackList>
    
    END;
    
    // loop through the array to build the track
    foreach($items as $key => $value)
    {
      $title = substr($key, 0, strlen($key) - 4);
      print <<<END
        <track>
          <creator>$creator</creator>
          <title>$title</title>
          <location>$url/$key</location>
        </track>
    
    END;
    }
    
    // closing tags
    print <<<END
      </trackList>
    </playlist>
    
    END;
    
    ?>
    Grazie!!!
    La vita è un percorso, goditi il viaggio.

  8. #8
    Utente di HTML.it L'avatar di carlo2002
    Registrato dal
    Jun 2002
    Messaggi
    2,746
    Codice PHP:

        
    if ( in_array($ext$filter) )
        {
    //////////////////////////////////////////// Windows debug code 
    hai una parentesi graffa di troppo, purtroppo avevo scritto sbagliato e devi aver copiato prima che lo correggessi.

    riprova...
    Errare humanum est, perseverare ovest

  9. #9
    Utente di HTML.it L'avatar di pariri
    Registrato dal
    Jul 2003
    Messaggi
    1,470
    Ok!!!! Funziona!!!!!

    Grazie mille!!!!!!!!!!

    La vita è un percorso, goditi il viaggio.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.