Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
PHP - Inserimento automatico dati
Forum - PHP - Inserimento automatico dati

Avatar
luigi7 (Normal User)
Pro


Messaggi: 83
Iscritto: 28/06/2011

Segnala al moderatore
Postato alle 21:36
Martedė, 27/12/2011
Salve, ho questo codice che mi inserisce solo un'immagine invece di inserire tutte le immagini che si trovano nella cartella selezionata.

Mi dite come posso fare per inserire tutte le immagini che si trovano nella cartella.

Codice sorgente - presumibilmente Php

  1. if(empty($_GET["cat"]))
  2. {
  3.  
  4. }else
  5. {
  6.  
  7.      if ($handle = opendir('../public/media/photo/'.$pieces[1].'/img_thumb/')) {
  8.      
  9.            while (false !== ($file = readdir($handle)))
  10.               {
  11.                   if ($file != "." && $file != "..")
  12.               {
  13.                    
  14.                    
  15.                    
  16.                    
  17.         $pieces = explode("|", addslashes($_POST["cat"]));
  18.         $strSQL = "INSERT INTO foto(_userid,";
  19.         $strSQL.="_catid,";
  20.         $strSQL.="_dir,";
  21.         $strSQL.="titolo,";
  22.         $strSQL.="testo,";
  23.         $strSQL.="url,";
  24.         $strSQL.="tag,";
  25.         $strSQL.="data,";
  26.         $strSQL.="active)";
  27.         $strSQL.= "VALUES('".$user_id."',";
  28.         $strSQL.="'".$pieces[0]."',";
  29.         $strSQL.="'".$pieces[1]."',";
  30.         $strSQL.="'".$file."',";
  31.         $strSQL.="'- Nessuna descrizione -',";
  32.         $strSQL.="'".$file."',";
  33.         $strSQL.="'',";
  34.         $strSQL.="'".$data."',";
  35.         $strSQL.="1)";
  36.        
  37.                   }
  38.                                    
  39.        
  40.                }
  41.                 $db->query($strSQL) or die($db->error);
  42.                
  43.         closedir($handle);
  44.         $db->close();
  45.                 $msg = "fatto";
  46.         echo $strSQL;
  47.                
  48.     }
  49.    
  50. }



grazie mille e scusate l'italiano ma non so come si chiama la cosa che fa quello che vorrei fare.

PM Quote
Avatar
luigi7 (Normal User)
Pro


Messaggi: 83
Iscritto: 28/06/2011

Segnala al moderatore
Postato alle 23:10
Martedė, 27/12/2011
risolto:
Codice sorgente - presumibilmente Php

  1. if(empty($_GET["cat"]))
  2. {
  3.  
  4. }else
  5. {
  6. //....
  7. $pieces = explode("|", addslashes($_POST["cat"]));
  8. $path='../public/media/photo/'.$pieces[1].'/img_thumb/';
  9. $imm=glob($path."*.*");
  10.  
  11. if(is_array($imm)){
  12. foreach($imm as $valore){// heredoc http://it2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
  13.     $valore=basename($valore);
  14.         $strSQL = <<< QUE
  15.     INSERT INTO foto(
  16.     _userid, _catid, _dir, titolo, testo, url,  tag, data, active)
  17.      VALUES('$user_id]', '$pieces[0]','$pieces[1]','$valore','- Nessuna descrizione -', '$valore', '', '$data', 1)
  18. QUE;
  19.     $db->query($strSQL) or die($db->error);
  20.     //....
  21. }
  22.  
  23. }
  24.    
  25. }


Ultima modifica effettuata da luigi7 il 27/12/2011 alle 23:10
PM Quote