• User Attivo

    image upload , resize e in database

    Ciao a tutti.....
    ho creato un database e un form tutto trovato in rete e messo in dreamweaver che in teoria dovrebbe inserirmi le immagini in 2 directory separate ,una per le imm.originali l'altra per le resize , nel db dovrebbe inserirmi il luogo , il titolo, il nome della immagine normale , il nome dell'immagine resize ......
    Mi aiutate a capire da questo codice come e' possibile fare questo....
    db
    -- phpMyAdmin SQL Dump
    -- version 2.10.3
    -- phpmyadmin.net

    -- Host: localhost
    -- Generato il: 17 Giu, 2008 at 08:57 PM
    -- Versione MySQL: 5.0.51
    -- Versione PHP: 5.2.6
    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

    -- Database: immagini


    --
    -- Struttura della tabella immagini

    CREATE TABLE immagini (
    id int(11) unsigned NOT NULL auto_increment,
    luogo varchar(255) NOT NULL,
    titolo varchar(255) NOT NULL,
    image_orig varchar(255) NOT NULL,
    image_small varchar(255) NOT NULL,
    PRIMARY KEY (id)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

    -- Dump dei dati per la tabella immagini


    codice php

    <?php require_once('Connections/immagini.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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"] == "something")) {
    $insertSQL = sprintf("INSERT INTO immagini (luogo, titolo, image_orig, image_small) VALUES (%s, %s, %s, %s)",
    GetSQLValueString($_POST['luogo'], "text"),
    GetSQLValueString($_POST['titolo'], "text"),
    GetSQLValueString($_POST['new_image'], "text"),
    GetSQLValueString($_POST['new_image'], "text"));
    mysql_select_db($database_immagini, $immagini);
    $Result1 = mysql_query($insertSQL, $immagini) or die(mysql_error());
    }
    ?><form name="something" action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" id="something" class="uniForm">
    <table width="424" border="0">
    <tr>
    <td height="31" colspan="3"><input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
    <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button></td>
    </tr>
    <tr>
    <td width="62"> </td>
    <td width="150"> </td>
    <td width="198"> </td>
    </tr>
    <tr>
    <td colspan="2"><label>
    <input name="luogo" type="text" id="luogo" size="30" />
    </label></td>
    <td>Luogo</td>
    </tr>
    <tr>
    <td> </td>
    <td> </td>
    <td> </td>
    </tr>
    <tr>
    <td colspan="2"><label>
    <input name="titolo" type="text" id="titolo" size="30" />
    </label></td>
    <td>Titolo</td>
    </tr>
    <tr>
    <td> </td>
    <td> </td>
    <td> </td>
    </tr>
    </table>
    <p> </p>
    <p> </p>
    <p> </p>
    <input type="hidden" name="MM_insert" value="something" />
    </form>
    <?php
    if(isset($_POST['submit'])){
    if (isset ($_FILES['new_image'])){
    $imagename = $_FILES['new_image']['name'];
    $source = $_FILES['new_image']['tmp_name'];
    $target = "images/".$imagename;
    move_uploaded_file($source, $target);

    $imagepath = $imagename;
    $save = "images_resize/" . $imagepath; //This is the new file you saving
    $file = "images/" . $imagepath; //This is the original file
    list($width, $height) = getimagesize($file) ;

    $modwidth = 150;

    $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 = "images/sml_" . $imagepath; //This is the new file you saving
    $file = "images/" . $imagepath; //This is the original file
    list($width, $height) = getimagesize($file) ;

    $modwidth = 80;

    $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) ;
    echo "Large image: <img src='images/".$imagepath."'><br>";
    echo "Thumbnail: <img src='images/sml_".$imagepath."'>";
    }
    }
    ?>

    GRAZIE MILLE:sun:
    vi allego 2 file per l'upload se interessano.......


  • ModSenior

    Dovresti dirci se ti genera un errore, oppure non hai idea di come fare tutto. Altrimenti è impossibile aiutarti( se non ti leggi 300 righe di codice e penso che in pochi lo faranno)


  • User Attivo

    OK..
    allora le immagini le carica nelle directory quindi tutto ok
    nel database non mi scrive il nome delle due immagini caricate (small e normale)
    grazie....


  • User Attivo

    penso sia qui' da risolvere l'errore....

    $insertSQL = sprintf("INSERT INTO immagini (luogo, titolo, image_orig, image_small) VALUES (%s, %s, %s, %s)",
    GetSQLValueString($_POST['luogo'], "text"),
    GetSQLValueString($_POST['titolo'], "text"),
    GetSQLValueString($_POST['new_image'], "text"),:smile5:
    GetSQLValueString($_POST['new_image'], "text"));


  • User Attivo

    Ho risolto
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")&& ($_FILES['new_image'])) {
    $insertSQL = sprintf("INSERT INTO immage (luogo, titolo, image_orig, image_small) VALUES (%s, %s, %s, %s)",
    GetSQLValueString($_POST['luogo'], "text"),
    GetSQLValueString($_POST['titolo'], "text"),
    GetSQLValueString($_FILES['new_image']['name'], "text"),
    GetSQLValueString($_FILES['new_image'] ['name'], "text"));

    ciaoooo:tongueout: