Ora ho la necessita di avere uno script che mi guarda le foto nelle varie cartelle e mi ineserice autoticamente..
Titolo
url
descrizione
data
attivo
Per ora ho fatto cosi però quando provo ad dare invia mi inserisce solo una invece tutte quelle che stanno nella cartella.
ATTENZIONE!!! non voglio salvare l'immagine nel db ma solo il nome "acquario.jpg".
ecco il codice che sto provando ad fare:
- <?php
- // Includo
- require_once(dirname(__FILE__) . '/../inc.php');
- require_once(dirname(__FILE__) . '/admin.php');
- require_once(dirname(__FILE__) . "/../template/".$template_admin."/header.php");
- global $thelist;
- $_cat = (isset($_GET["cat"])) ? trim ($_GET["cat"]): '';
- $pieces = explode("|", addslashes($_cat));
- $_url = (isset($_POST["_url"])) ? trim ($_POST["_url"]): '';
- if(isset($_POST["invia"]))
- {
- $pieces = explode("|", addslashes($_POST["cat"]));
- //$user = (isset($_POST["user"])) ? trim ($_POST["user"]): '';
- $user_id = (isset($_POST["user_id"])) ? trim ($_POST["user_id"]): '';
- $titolo = (isset($_POST["titolo"])) ? trim ($_POST["titolo"]): '';
- $testo = (isset($_POST["testo"])) ? trim ($_POST["testo"]): '';
- $data = date("d-m-Y");
- $tag = (isset($_POST["tag"])) ? trim ($_POST["tag"]): '';
- //$thelist = (isset($_POST["_url"])) ? trim ($_POST["_url"]): '';
- $_active = (isset($_POST["_active"])) ? trim ($_POST["_active"]): '';
- // Filtro i dati inviati se i magic_quotes del server sono disabilitati per motivi di sicurezza
- if (!get_magic_quotes_gpc()) {
- //$user = addslashes($user);
- $user_id = addslashes($user_id);
- $titolo = addslashes($titolo);
- $thelist = addslashes($thelist);
- $testo = addslashes($testo);
- $data = addslashes($data);
- $tag = addslashes($tag);
- $_active = addslashes($_active);
- }
- if(empty($_GET["cat"]))
- {
- }else
- {
- if ($handle = opendir('../public/media/photo/'.$pieces[1].'/img_thumb/')) {
- echo "Files:\n";
- // Lista di tutti i file:
- while (false !== ($file = readdir($handle))) {
- echo "$file\n";
- $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);
- $db->close();
- $msg = "fatto";
- echo $strSQL;
- closedir($handle);
- }
- }
- }
- ?>
- <p class="titolo">Aggiungi Foto</p>
- <?php
- if(isset($error)){ echo $error;}
- if(isset($msg)){ echo $msg;} else {
- ?>
- <form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>?cat=<?php echo "".$pieces[0]."|".$pieces[1].""; ?>">
- <table width="100%" align="center">
- <tr>
- <td></td>
- <td><input name="user_id" type="hidden" id="user_id" readonly value="<?php if(isset($_POST['user_id'])){echo $_POST['user_id'];}else { echo get_userID($_SESSION["user_crypt"]); }?>" /></td>
- </tr>
- <tr>
- <td>Seleziona Categoria</td>
- <td><?php echo "<select onchange=\"document.location.href = '" . $_SERVER['PHP_SELF'] . "?cat=' + this.value;\" name=\"cat\">";?>
- <option selected="selected" value="">Seleziona</option>
- <?php
- $result = $db->query("SELECT * FROM foto_categorie");
- while($row = $result->fetch_array())
- {
- $_cat= $row['titolo'];
- $id = $row['id'];
- ?>
- <option value="<?php echo $id; ?>|<?php echo $_cat; ?>"<?php if($pieces[0]=="".$id."") echo 'selected'?> ><?php echo $_cat; ?></option>
- <?php
- }
- ?>
- </select></td>
- </tr>
- </table>
- <?php
- ?></table>
- <input type="submit" value="Aggiungi Foto" name="invia" /> <input type="reset" value="Annulla Modifiche">
- </form>
- <?php
- }
- require_once(dirname(__FILE__) . "/../template/".$template_admin."/footer.php");
- ?>
mi dite come posso fare?
grazie mille.