Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    84

    Pagine con 2 form con azioni diverse

    Salve ragazzi, vi posto il mio problema:
    dunque ho una pagina per inserire dei prodotti e uno script trovato in rete per l' upload delle immagini. Ora come potrei unire le due cose? altrimentimenti dovrei prima effettuare l'upload della foto e poi nella pagina di inserimento far e di nuovo l'upload per fagli stampare il path.

    Il problema è che i form delle due pagine hanno diversi tipi di "azione"

    nella pagina di inserimento prodotti, l'azione è:
    <?php echo $editFormAction; ?>

    invece nella pagina dell'upload l'azione è:
    submit.php?subpage=upload


    questa è la pagina di inserimento prodotti:


    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    if (PHP_VERSION < 6) {
    $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"] == "form1")) {
    $insertSQL = sprintf("INSERT INTO prodotti (id_menu, codice, titolo, prezzo, foto, foto_thumbs, scheda) VALUES (%s, %s, %s, %s, %s, %s, %s)",
    GetSQLValueString($_POST['id_menu'], "text"),
    GetSQLValueString($_POST['codice'], "text"),
    GetSQLValueString($_POST['titolo'], "text"),
    GetSQLValueString($_POST['prezzo'], "double"),
    GetSQLValueString($_FILES['foto']['name'], "text"),
    GetSQLValueString($_FILES['foto']['name'], "text"),
    GetSQLValueString($_POST['scheda'], "text"));

    mysql_select_db($database_conn, $conn);
    $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
    }

    mysql_select_db($database_conn, $conn);
    $query_rs_menu = "SELECT * FROM menu ORDER BY nome_menu ASC";
    $rs_menu = mysql_query($query_rs_menu, $conn) or die(mysql_error());
    $row_rs_menu = mysql_fetch_assoc($rs_menu);
    $totalRows_rs_menu = mysql_num_rows($rs_menu);

    mysql_select_db($database_conn, $conn);
    $query_rs_inserisci_prodotto = "SELECT foto, foto_thumbs FROM prodotti";
    $rs_inserisci_prodotto = mysql_query($query_rs_inserisci_prodotto, $conn) or die(mysql_error());
    $row_rs_inserisci_prodotto = mysql_fetch_assoc($rs_inserisci_prodotto);
    $totalRows_rs_inserisci_prodotto = mysql_num_rows($rs_inserisci_prodotto);
    ?>



    questa è la pagina invece che fa l'upload della foto

    <?php
    $idir = "image_files/"; // Path To Images Directory
    $tdir = "image_files/thumbs/"; // Path To Thumbnails Directory
    $twidth = "120"; // Maximum Width For Thumbnail Images
    $theight = "125"; // Maximum Height For Thumbnail Images

    if (!isset($_GET['subpage'])) { // Image Upload Form Below ?>
    <table width="500" border="0" align="center" cellpadding="1" cellspacing="1">
    <tr>
    <th scope="col"><form method="post" action="submit.php?subpage=upload" enctype="multipart/form-data">
    File:

    <input type="file" name="foto" class="form">



    <input name="Carica la foto" type="submit" value="Carica la foto" class="form" id="Carica la foto">
    </form>
    <? } else if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') { // Uploading/Resizing Script
    $url = $_FILES['foto']['name']; // Set $url To Equal The Filename For Later Use
    if ($_FILES['foto']['type'] == "image/jpg" || $_FILES['foto']['type'] == "image/jpeg" || $_FILES['foto']['type'] == "image/pjpeg") {
    $file_ext = strrchr($_FILES['foto']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php
    $copy = copy($_FILES['foto']['tmp_name'], "$idir" . $_FILES['foto']['name']); // Move Image From Temporary Location To Permanent Location
    if ($copy) { // If The Script Was Able To Copy The Image To It's Permanent Location
    print 'Immagine caricata CORETTAMENTE.
    '; // Was Able To Successfully Upload Image
    $simg = imagecreatefromjpeg("$idir" . $url); // Make A New Temporary Image To Create The Thumbanil From
    $currwidth = imagesx($simg); // Current Image Width
    $currheight = imagesy($simg); // Current Image Height
    if ($currheight > $currwidth) { // If Height Is Greater Than Width
    $zoom = $twidth / $currheight; // Length Ratio For Width
    $newheight = $theight; // Height Is Equal To Max Height
    $newwidth = $currwidth * $zoom; // Creates The New Width
    } else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
    $zoom = $twidth / $currwidth; // Length Ratio For Height
    $newwidth = $twidth; // Width Is Equal To Max Width
    $newheight = $currheight * $zoom; // Creates The New Height
    }
    $dimg = imagecreate($newwidth, $newheight); // Make New Image For Thumbnail
    imagetruecolortopalette($simg, false, 256); // Create New Color Pallete
    $palsize = ImageColorsTotal($simg);
    for ($i = 0; $i < $palsize; $i++) { // Counting Colors In The Image
    $colors = ImageColorsForIndex($simg, $i); // Number Of Colors Used
    ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use
    }
    imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); // Copy Resized Image To The New Image (So We Can Save It)
    imagejpeg($dimg, "$tdir" . $url); // Saving The Image
    imagedestroy($simg); // Destroying The Temporary Image
    imagedestroy($dimg); // Destroying The Other Temporary Image
    print 'miniatura creata correttamente'; // Resize successful
    } else {
    print '<font color="#FF0000">ERROR: Unable to upload image.</font>'; // Error Message If Upload Failed
    }
    } else {
    print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is '; // Error Message If Filetype Is Wrong
    print $file_ext; // Show The Invalid File's Extention
    print '.</font>';
    }
    } ?>

  2. #2
    Utente di HTML.it L'avatar di telegio
    Registrato dal
    Sep 2001
    Messaggi
    2,592
    devi unire le due form in una sola.
    ti consiglio, visto che usi DW, di fare prima con il wizard l'insert del record, poi appresso a questa riga
    Codice PHP:
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { 
    (prima dell'inserimento)
    oppure dopo
    Codice PHP:
    $Result1 mysql_query($insertSQL$conn) or die(mysql_error()); 
    metti il codice dell'upload.
    PERO' ci sono delle precisazioni
    1 - cercati un altro script per l'upload, perchè questo è MOOOLTO datato: usa "copy", che non si usa più.. devi usare move_uploaded_file..
    2 - puoi eliminare il campo foto_thumbs, in quanto il nome della miniatura sarà SEMPRE uguale a quello della foto grande. a meno che nel gestionale che crei, poi puoi cambiare la miniatura indipendentemente dalla foto grande. ma te lo sconsiglio..

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    84
    Prima di tutto grazie mille per l'aiuto.
    Putroppo non sono riuscito a trovare in rete un altro script che carica la foto e ne crea un'altra ridimensionata, però tutto sommato sembra funzionare bene, almeno per il momento.

    Dunque ho seguito le tue istruzioni, molto probabilmente avrò sbagliato qualcosa, perchè effettua sempre una sola azione: se l'azione del form è <?php echo $editFormAction; ?> mi stampa tutti i dati, invece se metto inserisci_prodotto.php?subpage=upload mi carica solo la foto.

    Io ne capisco ben poco, ma il problema forse è qui, dovrei cambiare o eliminare qualcosa?

    nella pagina di inserimento ha
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {


    il codice di upload invece ha questa parte qui:

    <? } else if (isset($_POST['subpage']) && $_POST['subpage'] == 'upload') { // Uploading/Resizing Script


    ho provato anche a cambiare in questo modo ma effettua sempre solo una delle due azioni:
    <? } else if (isset($_POST['MM_insert']) && $_POST['MM_insert'] == 'form1') { // Uploading/Resizing Script

  4. #4
    Utente di HTML.it L'avatar di telegio
    Registrato dal
    Sep 2001
    Messaggi
    2,592
    devi fare una roba tipo:
    Codice PHP:
    <?php
    if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue "")
    {
    if (
    PHP_VERSION 6) {
    $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"] == "form1")) {
    $insertSQL sprintf("INSERT INTO prodotti (id_menu, codice, titolo, prezzo, foto, foto_thumbs, scheda) VALUES (%s, %s, %s, %s, %s, %s, %s)",
    GetSQLValueString($_POST['id_menu'], "text"),
    GetSQLValueString($_POST['codice'], "text"),
    GetSQLValueString($_POST['titolo'], "text"),
    GetSQLValueString($_POST['prezzo'], "double"),
    GetSQLValueString($_FILES['foto']['name'], "text"),
    GetSQLValueString($_FILES['foto']['name'], "text"),
    GetSQLValueString($_POST['scheda'], "text"));

    mysql_select_db($database_conn$conn);
    $Result1 mysql_query($insertSQL$conn) or die(mysql_error());

    // QUA INSERISCO L'UPLOAD DEL FILE!!!

    $idir "image_files/"// Path To Images Directory
    $tdir "image_files/thumbs/"// Path To Thumbnails Directory
    $twidth "120"// Maximum Width For Thumbnail Images
    $theight "125"// Maximum Height For Thumbnail Images

    $url $_FILES['foto']['name']; // Set $url To Equal The Filename For Later Use
    if ($_FILES['foto']['type'] == "image/jpg" || $_FILES['foto']['type'] == "image/jpeg" || $_FILES['foto']['type'] == "image/pjpeg") {
    $file_ext strrchr($_FILES['foto']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php
    $copy copy($_FILES['foto']['tmp_name'], "$idir$_FILES['foto']['name']); // Move Image From Temporary Location To Permanent Location
    if ($copy) { // If The Script Was Able To Copy The Image To It's Permanent Location
    print 'Immagine caricata CORETTAMENTE.
    '
    // Was Able To Successfully Upload Image
    $simg imagecreatefromjpeg("$idir$url); // Make A New Temporary Image To Create The Thumbanil From
    $currwidth imagesx($simg); // Current Image Width
    $currheight imagesy($simg); // Current Image Height
    if ($currheight $currwidth) { // If Height Is Greater Than Width
    $zoom $twidth $currheight// Length Ratio For Width
    $newheight $theight// Height Is Equal To Max Height
    $newwidth $currwidth $zoom// Creates The New Width
    } else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
    $zoom $twidth $currwidth// Length Ratio For Height
    $newwidth $twidth// Width Is Equal To Max Width
    $newheight $currheight $zoom// Creates The New Height
    }
    $dimg imagecreate($newwidth$newheight); // Make New Image For Thumbnail
    imagetruecolortopalette($simgfalse256); // Create New Color Pallete
    $palsize ImageColorsTotal($simg);
    for (
    $i 0$i $palsize$i++) { // Counting Colors In The Image
    $colors ImageColorsForIndex($simg$i); // Number Of Colors Used
    ImageColorAllocate($dimg$colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use
    }
    imagecopyresized($dimg$simg0000$newwidth$newheight$currwidth$currheight); // Copy Resized Image To The New Image (So We Can Save It)
    imagejpeg($dimg"$tdir$url); // Saving The Image
    imagedestroy($simg); // Destroying The Temporary Image
    imagedestroy($dimg); // Destroying The Other Temporary Image
    print 'miniatura creata correttamente'// Resize successful
    } else {
    print 
    '<font color="#FF0000">ERROR: Unable to upload image.</font>'// Error Message If Upload Failed
    }
    } else {
    print 
    '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is '// Error Message If Filetype Is Wrong
    print $file_ext// Show The Invalid File's Extention
    print '.</font>';
    }
    }



    }

    // ho tolto per semplificare i due recordset sotto..
    ?>
    vedi se va, io ho copiato e incollato le tue paginette togliendo solo le cose ovviamente errate..
    Dovrai poi mettere dei controlli se il file è vuoto, oppure se i campi testo sono vuoti e robe simili

  5. #5
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    84
    Posso dire che sei un grande?

    Ora me lo riguardo un pò per vedere cosa esattamente sbagliavo

  6. #6
    Utente di HTML.it L'avatar di telegio
    Registrato dal
    Sep 2001
    Messaggi
    2,592
    no, non puoi perchè non lo sono..

    usando anche io DW mi sono dovuto arrabattare per unire le cose..
    fammi sapere se ti funziona..
    non so come funzionano le funzioni "deprecate", se con l'avvento dei nuovi PHP magari non funzionano.. in questo caso, un giorno potresti trovarti con il famoso "copy" che non uploada più le immagini..

  7. #7
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    84
    Si funziona benissimo. Vabbè finchè funziona lo lasciamo

    Grazie mille!

  8. #8
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    84
    Salve a tutti, dopo l'aiuto di Telegio, che ringrazio ancora per avermi dato una mano ad unire le due pagine, volevo includere in questo stesso script la possibilità di fare un upload doppio, ho creato oltre alla tabella 'foto' una seconda 'varianti'. Ho provato a fare in questo modo, però mi restituisce l'errore che è contenuto nella pagina (ERRORE puoi inserire solo file che hanno questa estensione (.jpg or .jpeg. la tua è '...


    Codice PHP:

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
      
    $insertSQL sprintf("INSERT INTO prodotti (id, id_menu, id_sottomenu, titolo,lin, codice, foto, varianti) VALUES (%s,%s,%s,%s,%s,%s, %s, %s)",
                           
    GetSQLValueString($_POST['id'], "int"),
                           
    GetSQLValueString($_POST['id_menu'], "text"),
                           
    GetSQLValueString($_POST['id_sottomenu'], "text"),
                           
    GetSQLValueString($_POST['titolo'], "text"),
                           
    GetSQLValueString($_POST['lin'], "text"),
                           
    GetSQLValueString($_POST['codice'], "text"),
                           
    GetSQLValueString($_FILES['foto']['name'], "text"),
                           
    GetSQLValueString($_FILES['varianti']['name'], "text"));

      
    mysql_select_db($database_conn$conn);
      
    $Result1 mysql_query($insertSQL$conn) or die(mysql_error());


    // UPLOAD DEL FILE

    $idir "image_files/"// Path To Images Directory 
    $tdir "image_files/thumbs/"// Path To Thumbnails Directory 
    $twidth "120"// Maximum Width For Thumbnail Images 
    $theight "125"// Maximum Height For Thumbnail Images 



    $url $_FILES['foto'.$i.'varianti']['name']; // Set $url To Equal The Filename For Later Use 
    if ($_FILES['foto'.$i.'varianti']['type'] == "image/jpg" || $_FILES['foto'.$i.'varianti']['type'] == "image/jpeg" || $_FILES['foto'.$i.'varianti']['type'] == "image/pjpeg") { 
    $file_ext strrchr($_FILES['foto'.$i.'varianti']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php 
    $copy copy($_FILES['foto'.$i.'varianti']['tmp_name'], "$idir$_FILES['foto'.$i.'varianti']['name']); // Move Image From Temporary Location To Permanent Location 
    if ($copy) { // If The Script Was Able To Copy The Image To It's Permanent Location 
    print '. <font color="#FFFFFF">';// Was Able To Successfully Upload Image 
    $simg imagecreatefromjpeg("$idir$url); // Make A New Temporary Image To Create The Thumbanil From 
    $currwidth imagesx($simg); // Current Image Width 
    $currheight imagesy($simg); // Current Image Height 
    if ($currheight $currwidth) { // If Height Is Greater Than Width 
    $zoom $twidth $currheight// Length Ratio For Width 

    $newheight $theight// Height Is Equal To Max Height 
    $newwidth $currwidth $zoom// Creates The New Width 
    } else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) 
    $zoom $twidth $currwidth// Length Ratio For Height 
    $newwidth $twidth// Width Is Equal To Max Width 
    $newheight $currheight $zoom// Creates The New Height 

    $dimg imagecreate($newwidth$newheight); // Make New Image For Thumbnail 
    imagetruecolortopalette($simgfalse256); // Create New Color Pallete 
    $palsize ImageColorsTotal($simg); 
    for (
    $i 0$i $palsize$i++) { // Counting Colors In The Image 
    $colors ImageColorsForIndex($simg$i); // Number Of Colors Used 
    ImageColorAllocate($dimg$colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use 

    imagecopyresized($dimg$simg0000$newwidth$newheight$currwidth$currheight); // Copy Resized Image To The New Image (So We Can Save It) 
    imagejpeg($dimg"$tdir$url); // Saving The Image 
    imagedestroy($simg); // Destroying The Temporary Image 
    imagedestroy($dimg); // Destroying The Other Temporary Image 
    print 'Prodotto inserito con SUCCESSO <font color="#FFFFFF">'// Resize successful 
    } else { 
    print 
    '<font color="#FFFFFF">Errore riprova ad inserire il prodotto</font>'// Error Message If Upload Failed 

    } else { 
    print 
    '<font color="#FFFFFF">ERRORE puoi inserire solo file che hanno questa estensione (.jpg or .jpeg. la tua è '// Error Message If Filetype Is Wrong 
    print $file_ext// Show The Invalid File's Extention 
    print '.</font>'



  9. #9
    Utente di HTML.it L'avatar di telegio
    Registrato dal
    Sep 2001
    Messaggi
    2,592
    vuoi caricare 2 foto nello stesso record o vuoi inserire 2 record differenti?

  10. #10
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    84
    Praticamente l'oggetto dovrebbe avere due foto una front e un back, allora sarebbe necessario caricarne due di foto, però associate sempre nello stesso record, la prima foto andrebbe in 'foto' e l'altra in 'varianti'

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.