• User Attivo

    Problema con photogallery

    Ciao a tutti:)
    sto provando a fare un imagegallery casereccia....
    Ho fatto un form categorie dove creo la mia categoria e creo anche una directory con il nome della categoria creata in precedenza.

    Ho fatto un'altra pagina dove carico le mie immagini in base alla categoria creata e nella directory della categoria selezionata.

    Ora io ho creato il form di questa pagina
    <option value="<?php echo $row_category['id_categoria']?>"><?php echo $row_category['titolo']?></option>

    l'ho postato e qui' va bene
    ($_POST['id_categoria'], "int") (codice dreamweaver)

    Poi ho creato una variabile che mi richiama il post

    $categoria=$_POST['id_categoria'];

    Ma non va...
    Ho provato cosi' ma mi inserisce l'immagine solo nella prima directory creata

    $categoria=$row_category['titolo'];

    Ho inserito la variabile nella directory dove mettere la foto
    $target = "../foto/immagine_originale/$categoria/".$imagename;

    Mi date una mano???:smile5::smile5:


  • User Attivo

    Ciao patatrac,
    ci si capisce veramente poco...

    Cerca di chiarire meglio il problema, segnalando esattamente l'errore e il motivo dei frammenti di codice che hai postato...

    Considera che tu conosci esattamente il problema che stai affrontando ma noi no!

    :ciauz:


  • User Attivo

    mysql database
    --categoria
    id_categoria
    titolo
    testo

    --news
    id
    id_categoria
    data
    titolo
    testo
    immagine_originale
    immagine_media
    immagine_piccola

    pagina categoria

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
    {
    $insertSQL = sprintf("INSERT INTO categoria (data, titolo, testo) VALUES (%s, %s, %s)",
    GetSQLValueString($_POST['data'], "text"),
    GetSQLValueString($_POST['titolo'], "text"),
    GetSQLValueString($_POST['testo'], "text"));
    mysql_select_db($database_cnx, $cnx);
    $Result1 = mysql_query($insertSQL, $cnx) or die(mysql_error());
    $insertGoTo = "inserimento_effettuato.php";
    if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    //aggiunto codice
    $cat=$_POST['titolo'];
    if ($_POST['titolo'])
    {
    chdir('../foto/immagine_originale/');
    $create_orig = @mkdir($cat); // create directory in originale
    }
    }
    header(sprintf("Location: %s", $insertGoTo));
    }
    ?>

    pagina news

    <?php
    mysql_select_db($database_cnx, $cnx);
    $query_category = "SELECT id_categoria, titolo FROM categoria";
    $category = mysql_query($query_category, $cnx) or die(mysql_error());
    $row_category = mysql_fetch_assoc($category);
    $totalRows_category = mysql_num_rows($category);
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")&& ($_FILES['new_image']))
    {
    $categoria=$row_category['titolo'];
    $imagename = $_FILES['new_image']['name'];
    $source = $_FILES['new_image']['tmp_name'];
    $target = "../foto/immagine_originale/$categoria/".$imagename;
    $imagepath = $imagename;
    $allowed_filetypes = array('.JPG','.jpg','.gif','.bmp','.PNG','.png','.GIF','.tif','.tiff','.ai','.psd','.jpeg','.JPEG');
    $ext = substr($imagename, strpos($imagename,'.'), strlen($imagename)-1);
    if(!in_array($ext,$allowed_filetypes))
    die("Il file da caricare non e' del tipo ammesso ");
    }
    if(file_exists($target))
    {
    die("Il file nella cartella remota esiste gia'. Rinominarlo");
    }
    if (move_uploaded_file($source, $target))
    {
    $insertSQL = sprintf("INSERT INTO news (id_categoria,data, titolo, testo ,immagine_originale ,immagine_media ,immagine_piccola) VALUES (%s, %s, %s ,%s, %s, %s, %s)",
    GetSQLValueString($_POST['id_categoria'], "int"),
    GetSQLValueString($_POST['data'], "text"),
    GetSQLValueString($_POST['titolo'], "text"),
    GetSQLValueString($_POST['testo'], "text"),
    GetSQLValueString($_FILES['new_image']['name'], "text"),
    GetSQLValueString($_FILES['new_image']['name'], "text"),
    GetSQLValueString($_FILES['new_image']['name'], "text"));
    mysql_select_db($database_cnx, $cnx);
    $Result1 = mysql_query($insertSQL, $cnx) or die(mysql_error());
    $insertGoTo = "inserimento_effettuato.php";
    if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s", $insertGoTo));
    $cat=$_POST['id_categoria'];
    if ($POST['id_categoria'])
    {
    echo $cat;
    }
    //SECONDO RESIZE 150
    $save = "../foto/immagine_originale/md
    /$categoria/" . $imagepath; //This is the new file you saving
    $file = "../foto/immagine_originale/$categoria/" . $imagepath; //This is the original file
    list($width, $height) = getimagesize($file) ;

    $modwidth = 300;

    $diff = $width / $modwidth;

    $modheight = $height / $diff;
    $tn = imagecreatetruecolor($modwidth, $modheight) ;
    $image = imagecreatefromjpeg($file) ;
    imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

    imagejpeg($tn, $save, 100) ;

    $save = "../foto/immagine_originale/pc_/$categoria/" . $imagepath; //This is the new file you saving
    $file = "../foto/immagine_originale/$categoria/" . $imagepath; //This is the original file
    list($width, $height) = getimagesize($file) ;

    $modwidth = 100;

    $diff = $width / $modwidth;

    $modheight = $height / $diff;
    $tn = imagecreatetruecolor($modwidth, $modheight) ;
    $image = imagecreatefromjpeg($file) ;
    imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

    imagejpeg($tn, $save, 100) ;
    }

    ?>
    <

    <td colspan="6" align="center" valign="top" background="../immagini/index_38.gif"><br>
    <form name="form1" action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" id="something" class="uniForm">
    <p>
    <label></label>
    <br>
    </p>
    <table width="447" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="3" align="center" class="titolo">INSERISCI LE TUE NEWS</td>
    </tr>
    <tr>
    <td align="right" class="testo"> </td>
    <td colspan="2" align="right"><a href="../categoria/inserisci.php">categorie</a></td>
    </tr>
    <tr>
    <td align="right" class="testo"> </td>
    <td colspan="2"><label>
    <select name="id_categoria" id="id_categoria">
    <option value="">Categorie</option>
    <?php
    do {
    ?>
    <option value="<?php echo $row_category['id_categoria']?>"><?php echo $row_category['titolo']?></option>
    <?php
    } while ($row_category = mysql_fetch_assoc($category));
    $rows = mysql_num_rows($category);
    if($rows > 0) {
    mysql_data_seek($category, 0);
    $row_category = mysql_fetch_assoc($category);
    }
    ?>