Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1

    form inserimento record + upload file

    ciao a tutto,
    sto costruendo 1 form per l'invio dei dati in una tabella di mysql (cosa che normalmente faccio con DW) ma ora mi occorre anche l'inserimento di 2 foto e li qualche problema c'e'!
    posto il codice php e html
    pleease help me!

    <?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"] == "aggiunta")) {
    $insertSQL = sprintf("INSERT INTO oggetti (cod_oggetto, nome_oggetto, descrizione_parziale, descrizione_completa, prezzo, quantita, foto_anteprima, foto_ingrandita, categoria) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
    GetSQLValueString($_POST['codice_prodotto'], "text"),
    GetSQLValueString($_POST['nome_prodotto'], "text"),
    GetSQLValueString($_POST['descrizione_parziale'], "text"),
    GetSQLValueString($_POST['descrizione_completa'], "text"),
    GetSQLValueString($_POST['prezzo'], "text"),
    GetSQLValueString($_POST['quantita'], "text"),
    GetSQLValueString($_POST['file1'], "text"),
    GetSQLValueString($_POST['file2'], "text"),
    GetSQLValueString($_POST['categoria'], "text"));

    mysql_select_db($database_conn_aquolina, $conn_aquolina);
    $Result1 = mysql_query($insertSQL, $conn_aquolina) or die(mysql_error());
    }
    ?>

    --------------------------------------------------------------------------------------

    <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="aggiunta" id="aggiunta">

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="16%" align="right">Codice prodotto</td>
    <td width="1%"></td>
    <td width="83%"><input type="text" name="codice_prodotto" id="codice_prodotto" /></td>
    </tr>
    <tr>
    <td colspan="3" height="5"></td>
    </tr>
    <tr>
    <td align="right">Nome prodotto</td>
    <td></td>
    <td><input type="text" name="nome_prodotto" id="nome_prodotto" /></td>
    </tr>
    <tr>
    <td colspan="3" height="5"></td>
    </tr>
    <tr>
    <td align="right">Descrizione parziale</td>
    <td></td>
    <td><input type="text" name="descrizione_parziale" id="descrizione_parziale" /></td>
    </tr>
    <tr>
    <td colspan="3" height="5"></td>
    </tr>
    <tr>
    <td align="right">Descrizione completa</td>
    <td></td>
    <td><input type="text" name="descrizione_completa" id="descrizione_completa" /></td>
    </tr>
    <tr>
    <td colspan="3" height="5"></td>
    </tr>
    <tr>
    <td align="right">Prezzo</td>
    <td></td>
    <td><input type="text" name="prezzo" id="prezzo" /></td>
    </tr>
    <tr>
    <td colspan="3" height="5"></td>
    </tr>
    <tr>
    <td align="right">Categoria</td>
    <td></td>
    <td><input type="text" name="categoria" id="categoria" /></td>
    </tr>
    <tr>
    <td colspan="3" height="5"></td>
    </tr>
    <tr>
    <td align="right">Quantita'</td>
    <td></td>
    <td><input type="text" name="quantita" id="quantita" /></td>
    </tr>
    <tr>
    <td colspan="3" height="5"></td>
    </tr>
    <tr>
    <td align="right">Foto in anteprima</td>
    <td></td>
    <td><input type="file" name="file1" id="foto_anteprima" /></td>
    </tr>
    <tr>
    <td colspan="3" height="5"></td>
    </tr>
    <tr>
    <td align="right">Foto ingrandita</td>
    <td></td>
    <td><input type="file" name="file2" id="foto_ingrandita" /></td>
    </tr>
    <tr>
    <td colspan="3" height="10"></td>
    </tr>
    <tr>
    <td></td>
    <td></td>
    <td><input type="submit" name="aggiungi" id="aggiungi" value="Upload" /></td>
    </tr>
    </table>

    <input type="hidden" name="MM_insert" value="aggiunta" />
    </form>

  2. #2
    mmm fammi indovinare: non salva niente nel DB ne carica i file?

    dai un'occhiata a questo: http://it.php.net/manual/it/function...oaded-file.php

    e questo: http://it.php.net/manual/it/reserved...bles.files.php

  3. #3
    si esatto, carica tutti i campi ma non quei due che richiedono l'immagine.
    ho letto nel forum che bisognerebbe indicare anche la cartella nalla quale salvare l'immagine ma sinceramente non ho capito come fare e dove inserire il comando.

  4. #4
    e i link che ti ho messo secondo te sono solo per bellezza?

  5. #5
    nn per bellezza ma non saprei dove inserirli e cosa cambiare del mio codice

  6. #6
    leggere ti da problemi?

    Ok, in parole povere: quando invii una form com multipart/form-data PHP salva le variabili che non sono TESTO (ovvero quello che gli passi con input file) in un'altro array predefinito, non $_POST, ma $_FILE.
    (Nel secondo link c'è la lista delle proprietà passate col suddetto array)

    Per accedere, ad esempio, al nome del file passato nell'input name="file1" devi fare $_FILE['file1']['name'], per la dimensione $_FILE['file1']['size'], e così via per file 2 etc.

    Se apri il primo link che ti ho passato, e leggi sotto la descrizione della funzione, c'è un esempio di come move_uploaded_file funziona.

  7. #7
    scusami ma ti chiedo 1 po di pazienza...

    in pratica ho cambiato la stringa
    GetSQLValueString($_POST['file1'], "text"),
    in:
    GetSQLValueString($HTTP_POST_FILES['file1'], "text"),

    cosa scrivo al posto di "text"?
    e i campi della tabella che tipo di file richiede? (io avevo impostato testo ma e' sbagliato vero?)

  8. #8
    per il db devi fare:

    GetSQLValueString($_FILES['file1']['name'], "text"),
    GetSQLValueString($_FILES['file2']['name'], "text"),

    leggi questo link:

    http://it.php.net/manual/it/features.file-upload.php

    Poi per salvare i file sul server devi fare:

    $target1 = "tuo/percorso/".basename($_FILES['file1']['name']) ;
    $target2 = "tuo/percorso/".basename($_FILES['file2']['name']) ;

    move_uploaded_file($_FILES['file1']['tmp_name'],$target1);
    move_uploaded_file($_FILES['file2']['tmp_name'],$target2);

  9. #9
    grande artorius!!
    funziona tutto correttamente!!
    graciass

  10. #10
    ho cantato vittoria troppo presto... funzionava in locale ma uplodato sul server mi da 1 errore:

    Warning: move_uploaded_file(immagini_prew/immagine.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\Inetpub\webs\acquolinashopcom\inserimento_prodo tto.php on line 79

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\PHP\upload\php3774.tmp' to 'immagini_prew/immagine.jpg' in D:\Inetpub\webs\acquolinashopcom\inserimento_prodo tto.php on line 79

    mi carica tutto correttamente ma le immagini non le sposta nelle cartelle indicate...
    help!!

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 © 2025 vBulletin Solutions, Inc. All rights reserved.