Visualizzazione dei risultati da 1 a 5 su 5

Discussione: inserimento foto

  1. #1

    inserimento foto

    ciao a tutti!

    ho questo codice e vorrei riuscire ad inserire un'immagine nel db

    <?php
    include('function/config.inc');
    session_start();

    $flag = $_POST['flag'];
    $nome = $_POST['nome'];
    $cognome = $_POST['cognome'];
    $user =$_POST['user'];
    $password = $_POST['password'];
    $mail = $_POST['mail'];
    $ruolo = $_POST['ruolo'];

    if (is_uploaded_file($_FILES['foto']['tmp_name'])) {

    $foto = "../fototeam/".$_FILES['foto']['name'];
    move_uploaded_file($_FILES['foto']['tmp_name'],$foto);
    }
    else { $foto = ""; }

    if ($flag == 99) {

    $query="INSERT INTO utenti (nome,cognome,user,password,mail,ruolo,foto) VALUES ('$nome','$cognome','$user','$password','$mail','$ ruolo','$foto')";

    // echo "QUERY INSERIMENTO: ".$query;

    mysql_query($query,$connessione) or die('Could not connect:' .mysql_error());

    }




    ?>



    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>

    <title>Inserisci nel team!</title>
    </head>
    <body>
    <center>
    <h1>Inserisci nel team!</h1>




    <form action="inserisciteam2.php" method="post" style="border: medium solid red;"class="modulo" enctype="multipart/form-data">
    <input type="hidden" name="flag" value="99">
    <table border="0" cellspacing="5" cellpadding="6" width="350">
    <tr>
    <td width="150">Nome:</td>
    <td width="200"><input type="text" name="nome"></td>
    </tr>
    <tr>
    <td width="150">Cognome:</td>
    <td width="200"><input type="text" name="cognome"></td>
    </tr>
    <tr>
    <td width="150">User:</td>
    <td width="200"><input type="text" name="user" value=""></td>
    </tr>
    <tr>
    <td width="150">Password:</td>
    <td width="200"><input type="text" name="password" value=""></td>
    </tr>
    <tr>
    <td width="150">E-mail:</td>
    <td width="200"><input type="text" name="mail"></td>
    </tr>
    <tr>
    <td width="150">Ruolo:</td>
    <td width="200"><input type="text" name="ruolo"></td>
    </tr>

    <tr>
    <td width="150">Foto:</td>
    <td width="200"><input type="file" name="foto"></td>
    </tr>


    <tr>
    <td width="150"><input type="reset" value="Svuota Modulo"></td>
    <td width="200"><input type="submit" name="submit" value="Inserisci"></td>
    </tr>
    </table>
    </form>

    </center>
    </body>
    <?php
    mysql_close($connessione);
    ?>
    </html>


    la cosa che nn mi torna è che l'immagine appare nella tabella del db come percorso, ma non appare nella cartella "fototeam".
    come mai?

  2. #2
    Utente di HTML.it L'avatar di izzusan
    Registrato dal
    Apr 2003
    Messaggi
    463
    questo codice funziona sicuro fa anche controlli su cosa inserisci


    $percorso="../script/img/galleria_immagini/big/";
    $userfile_name = $_FILES["immagine"]["name"];
    $nome_file = md5(dimminomefile($userfile_name));
    $tipofile = tipo_file($userfile_name);

    if((trim($tipofile) <> "jpg") and (trim($tipofile) <> "jpeg") and (trim($tipofile) <> ""))
    {
    //cancello l'immagine appena uploadata
    @unlink($percorso.$userfile_name);
    echo "ATTENZIONE! L'immagine deve avere estensione '.jpg' o '.jpeg'";
    echo "

    <a href=\"news_nuova.php\">Torna indietro</a>";
    exit;
    }
    else{

    if(isset($_FILES["immagine"]) && $_FILES["immagine"]["size"]>0)
    {

    if (!move_uploaded_file($_FILES['immagine']['tmp_name'], $percorso . $nome_file . "." . $tipofile))
    {
    print "Problemi con l'upload del file! Il file non è stato caricato.";
    exit;
    }
    else
    {

    $strFoto = $nome_file . "." . $tipofile;

    $percorso_new="../script/img/galleria_immagini";

    crea_immagine($percorso,$percorso_new,$nome_file,$ tipofile,GALLERY_WIDTH,"");


    }
    }
    else
    {
    $strFoto = "";
    }
    }

  3. #3
    Utente di HTML.it L'avatar di izzusan
    Registrato dal
    Apr 2003
    Messaggi
    463
    $strfoto sara il tuo campo da inserire nel db

  4. #4
    Utente di HTML.it L'avatar di telegio
    Registrato dal
    Sep 2001
    Messaggi
    2,591
    ho preso SOLO il codice dell'upload e a me funziona.
    sei per caso sotto windows?

  5. #5
    no sn con ubuntu

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.