Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 20

Discussione: inserimento foto

  1. #1

    inserimento foto

    ciao a tutti!
    ho questo codice per inserire una persona all'interno della tabella team sul mio 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 ($flag == 99) {

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

    // 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>



    <?php

    $user = $_SESSION['utente'];

    $sql = "SELECT grado FROM utenti WHERE user='$user'";

    $result=mysql_query($sql);

    while ($row = mysql_fetch_array($result)) {

    $_SESSION['grado'] = $row['grado'];

    }



    ?>

    <form action="inserisci_team.php" method="post" style="border: medium solid red;"class="modulo">

    <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"><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>
    Codice PHP:
    <?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 ($flag == 99) {            $query="INSERT INTO utenti (nome,cognome,user,password,mail,ruolo) VALUES ('$nome','$cognome','$user','$password','$mail','$ruolo')";  //       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>        <?php        $user $_SESSION['utente'];          $sql "SELECT grado FROM utenti WHERE user='$user'";          $result=mysql_query($sql);          while ($row mysql_fetch_array($result)) {           $_SESSION['grado'] = $row['grado'];        }        ?>         <form action="inserisci_team.php" method="post" style="border: medium solid red;"class="modulo">        <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"><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>
    però oltre a nome, cognome ecc vorrei anche inserire una foto della persona. come faccio?

  2. #2
    ci sono due solizioni:

    1. inserire l'immagine nel database in un campo BLOB (sconsigliato)
    2. uploadare l'immagine sul webserver e salvare il percorso dell'immagine in un campo della tabella (consigliato)

    quale dei due vorresti usare??
    V.I.S.T.A. --> Virus Inside, Switch To Apple

  3. #3
    naturalmente la seconda ^^
    ho già creato un campo "foto" nella tabella e gli ho dato varchar.

    ho modificato il codice di prima:

    <?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'];
    $foto = $_POST['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>



    <?php

    $user = $_SESSION['utente'];

    $sql = "SELECT grado FROM utenti WHERE user='$user'";

    $result=mysql_query($sql);

    while ($row = mysql_fetch_array($result)) {

    $_SESSION['grado'] = $row['grado'];

    }



    ?>

    <form action="inserisci_team.php" method="post" style="border: medium solid red;"class="modulo">

    <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>

    ma se provo a caricare nel campo "foto" della tabella nn si vede niente

  4. #4
    perfetto....allora naturalmente la form deve avere impostato l'enctype su:

    enctype="multipart/form-data"

    per quanto riguarda la parte php

    Codice PHP:

    if (is_uploaded_file($_FILES['foto']['tmp_name'])) { 
        
    move_uploaded_file($_FILES['foto']['tmp_name'],"percorso-cartella-destinazione-foto/".$_FILES['foto']['name']); 
    //al posto di $_FILES['foto'] ci devi mettere $_FILES['nome-del-tuo-campo-input-file']

    nel database vai a salvare "percorso-cartella-destinazione-foto/".$_FILES['foto']['name']
    poi per visualizzare la foto fai

    [img]'.[variabile ottenuta dalla query (quella che contiene il percorso)].'[/img]
    V.I.S.T.A. --> Virus Inside, Switch To Apple

  5. #5
    allora l'enctype l'ho messo.

    il codice php che mi hai postato dove lo devo incollare?


    così va bene?

    <?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'];
    $foto = $_POST['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());

    }



    if (is_uploaded_file($_FILES['foto']['tmp_name'])) {
    move_uploaded_file($_FILES['foto']['tmp_name'],"SitoHand/fototeam/".$_FILES['foto']['name']);
    //move_uploaded_file($_FILES['foto']['tmp_name'],"percorso-cartella-destinazione-foto/".$_FILES['foto']['name']);
    }


    ?>





    <!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="inserisci_team.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>


    scusa ma sn nuovissima ^^

  6. #6
    eheh....vabbe ti scrivo tutto io :P....prima di tutto crea una cartella nella document root e chiamala "foto" (ovviamente senza doppi apici)

    Codice PHP:

    <?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'])) { 
        
    move_uploaded_file($_FILES['foto']['tmp_name'],"foto/".$_FILES['foto']['name']);
        
    $foto "foto/".$_FILES['foto']['name'];
    }
    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());

    }

    ?>
    V.I.S.T.A. --> Virus Inside, Switch To Apple

  7. #7
    ti do un altro consiglio...presumo che nel file config.inc ci siano i parametri per la connessione al database....beh se è cosi cambia l'estensione del file in .php....perche se un utente digita www.tuosito.com/config.inc vede tutti i tuoi bei dati di accesso (e la cosa non è carina)...se invece gli dai estensione .php il web server interpreta il codice all'interno (e non essendoci degli echo visualizza una pagina bianca)
    V.I.S.T.A. --> Virus Inside, Switch To Apple

  8. #8
    aspetta aspetta XD la document root sarebbe la cartella www???

  9. #9
    cmq il mio file si kiama già config.inc.php
    va bene no???

  10. #10
    si...........XD.....

    tutto cio presupponendo che il file php che esegue l'inserimento dell'utente sia nella document root...altrimenti al posto di "foto/".$_FILES['foto']['name']) devi mettere:

    "../foto/".$_FILES['foto']['name'])

    il ../ tante volte quante directory "all'indietro devi andare" ...mi spiego..supponiamo che tu abbia una configurazione del genere


    [ www ]
    [ cartella ]
    [ foto ]
    [ script]
    [ registrazione ]
    file che esegue l'inserimento.php

    ora il tuo file.php è dentro la cartella registrazione....se scrivi "../foto/".$_FILES['foto']['name']) php suppone di trovare dentro la cartella [ script ] (directory padre) una cartella di nome foto

    allora per scrivere in modo corretto questo esempio dovresti scrivere
    "../../foto/".$_FILES['foto']['name'])

    spero di aver reso l'idea
    V.I.S.T.A. --> Virus Inside, Switch To Apple

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.