Oppure

Loading
27/12/11 20:36
luigi7
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.

     if(empty($_GET["cat"]))
{

}else
{

     if ($handle = opendir('../public/media/photo/'.$pieces[1].'/img_thumb/')) {
     
           while (false !== ($file = readdir($handle)))
              {
                  if ($file != "." && $file != "..")
              {
                    
                   
                    
                    
        $pieces = explode("|", addslashes($_POST["cat"]));
        $strSQL = "INSERT INTO foto(_userid,";
        $strSQL.="_catid,";
        $strSQL.="_dir,";
        $strSQL.="titolo,";
        $strSQL.="testo,";
        $strSQL.="url,";
        $strSQL.="tag,";
        $strSQL.="data,";
        $strSQL.="active)";
        $strSQL.= "VALUES('".$user_id."',";
        $strSQL.="'".$pieces[0]."',";
        $strSQL.="'".$pieces[1]."',";
        $strSQL.="'".$file."',";
        $strSQL.="'- Nessuna descrizione -',";
        $strSQL.="'".$file."',";
        $strSQL.="'',";
        $strSQL.="'".$data."',";
        $strSQL.="1)";
        
                  }
				   
       
               } 
		$db->query($strSQL) or die($db->error);
		
        closedir($handle); 
        $db->close();
		$msg = "fatto";
        echo $strSQL;
		
    }
    
}


grazie mille e scusate l'italiano ma non so come si chiama la cosa che fa quello che vorrei fare.
aaa
27/12/11 22:10
luigi7
risolto:
       if(empty($_GET["cat"]))
{

}else
{
//....
$pieces = explode("|", addslashes($_POST["cat"]));
$path='../public/media/photo/'.$pieces[1].'/img_thumb/';
$imm=glob($path."*.*");

if(is_array($imm)){
foreach($imm as $valore){// heredoc http://it2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
    $valore=basename($valore); 
	$strSQL = <<< QUE
    INSERT INTO foto(
    _userid, _catid, _dir, titolo, testo, url,  tag, data, active)
     VALUES('$user_id]', '$pieces[0]','$pieces[1]','$valore','- Nessuna descrizione -', '$valore', '', '$data', 1)
QUE;
    $db->query($strSQL) or die($db->error);
    //....
}

} 
    
}
Ultima modifica effettuata da luigi7 27/12/11 22:10
aaa