| Home  | Casa  | Hardware  | Networking  | Programmazione  | Software  | Domanda  | Sistemi  |   
Programmazione  
  • C /C + + Programming

  • Computer Programming Languages

  • Delphi Programming

  • Java Programming

  • Programmazione Javascript

  • PHP /MySQL Programmazione

  • Perl Programming

  • Python Programming

  • rubino Programmazione

  • Nozioni di base di Visual Programming
  •  
    Conoscenza Informatica >> Programmazione >> PHP /MySQL Programmazione >> Content
    Come Upload & Ridimensionamento di un PHP MySQL Immagine
    Quando si tratta di una grande quantità di immagini , è spesso utile per memorizzarli in un database . Questo rende l'accesso e la modifica delle immagini facile e snella , anche quando è necessario cambiare più di uno alla volta . Un compito comune eseguita sulle immagini memorizzate è quello di ridimensionare l'immagine . Caricamento e ridimensionamento di un'immagine con PHP e MySQL può essere molto semplice , e permette di fare molte cose, come creare una serie di miniature per la tua galleria di immagini , o semplicemente visualizzare una determinata immagine in un formato diverso da quello originale . Cose che ti serviranno
    Web hosting con PHP e MySQL installati
    Mostra più istruzioni
    1

    creare il database e la tabella in MySQL . Utilizzando l'interfaccia di MySQL , eseguire i seguenti comandi :

    CREATE DATABASE test ;
    test USO

    ;

    creare immagini tabella (

    image_id di serie , < br >

    filename varchar ( 255 ) NOT NULL , Stati

    mime_type varchar ( 255 ) NOT NULL , Stati

    file_size int not null , Stati

    file_data LONGBLOB non nullo, < br tasto>

    primaria ( image_id ) , Stati indice

    (filename ) per

    ) ;
    2

    Utilizzare un editor di testo per creare un file di nome " image_upload . html " e riempirlo con il codice qui sotto . Questo sarà il modulo per selezionare la vostra immagine con .



    Caricare un'immagine < /title> < br > <p> < /head> <br> <p> <body> <br> <p> <div> <br> <p> <h1> caricare un'immagine < /h1 > <br> < p > <form method="post" action="image_insert.php" enctype="multipart/form-data"> <br> <p> <div> <br> <p> < input type = " "name = " file immagine " /> <br> <p> < input type = " " value =" submit Caricare l'immagine " <br> 3 <p> Creare un file denominato " connect.php " e riempirlo con il codice qui sotto . Questo sarà lo script che consente gli altri file per utilizzare il database . Utilizzare il proprio nome utente e la password al posto del " $ Onu " e " $ pw " valori compresi <br> <p> < php <br> <p> $ host = " localhost" ; . ? $ Un = "root " ; $ pw = " password "; $ db = " test " ; <br> <p> $ link = mysqli_connect ( $ host , $ ONU , $ pw , $ db ) ; ! <br> <p> if ( $ link) { die ( ' Dannazione, collegamento non stabilito . '); exit ; } <br> <p> $ db = "test" ; <br> <p> $ db = mysqli_select_db ( $ link , $ db ) ; <br> <p> if ( $ link ) { <br> <p> die ( 'Errore Connect ( ' mysqli_connect_errno ( ) ') ' <br> <p> mysqli_connect_error () . . . ) ; <br> < p > se { <br> <p> echo " Impossibile stabilire una connessione al server di database"; <br> uscita <p> ; <br> <p> } ( $ link! ) per <p> se ( mysqli_select_db ! ( $ link , 'test' )) { <br> <p> echo " Impossibile connettersi al database"; <br> uscita <p> ; <br> <p> } <br> <p> > < ? br> <br> 4 <p> Creare un file denominato " image_insert.php " e riempirlo con il codice qui sotto . Questo file avrà i dati di immagine che inviamo dalla forma , e posizionarlo nella vostra tabella immagini . Se non vi è nessuna immagine passato a questo file , verrà restituito un errore per voi <br> <p> < php <br> <p> require_once ( ' connect.php '); . ? <br> <p> Se { die ( ' Non più ! '); } ( $ _FILES [' immagine '] ! ) <p> <br> $ immagine = $ _FILES [' immagine '] ; <br> <p> print_r ( $ immagine ) ; <br> <p> $ query = sprintf ( <br> <p> " INSERT INTO immagini (filename , mime_type , file_size , file_data ) <br> <p> VALUES ( '% s' , '% s' , % d , ( $ risultato = mysqli_query ( $ link , $ query ) ) { die ( ' Merda è accaduto quando si cerca di inserire nella tabella ' mysqli_error ( $ link) . );} <br> <p> $ id = (int ) mysqli_insert_id ( $ link) ; <br> header <p> ( 'Posizione: ? image_view.php id =' . è stato un errore nel codice, oppure il file non può essere caricato per un altro motivo . < /p > <br> <p> <br> <p> href="image_upload.php"> , Torna indietro < /a> <br> </p > <br> <p> < /div > <br> <p> < /body> <br> <p> < /html > ; <br> 5 <p> Creare un file denominato " image_view.php " e salvare il codice qui sotto in esso Questo file tirerà l'immagine dal database e mostrare a voi in qualsiasi dimensione che si desidera il . . codice di seguito ha l'immagine visualizzata a 500 pixel per 500 pixel <br> <p> < php <br> <p> require_once ( ' connect.php '); . ? <br> <p> $ desired_width = 500 ; <br> <p> $ desired_height = 500; <br> <p> $ id = ( int ) $ _GET [ 'id' ] ; <br> <p> $ query = "SELECT * FROM immagini WHERE image_id = $ id " ; <br> <p> $ risultato = mysqli_query ( $ link , $ query ) ; <br> <p> $ image = mysqli_fetch_array ( $ risultato) ; <br> <p> mysqli_close ( $ link) ; <br> < p > $ blobcontents = $ immagine [' file_data '] ; <br> <p> $ im = imagecreatefromstring ( $ blobcontents ) ; <br> <p> $ nuovo = imagecreatetruecolor ( $ desired_width , $ desired_height ) ; <br> < p > $ x = imagesx ( $ im ) ; <br> <p> $ y = imagesy ( $ im ) ; <br> <p> imagecopyresampled ( $ nuovo , $ im , 0 , 0 , 0 , 0 , $ desired_width , $ desired_height , $ x , $ y ) ; <br> <p> imagedestroy ( $ im ) ; <br> header <p> ( ' Content-type: image /jpeg '); <br> <p> imagejpeg ( $ nuovo , null , 85) ; ? <br> <p> > <br> 6 <p> individuare il file image_upload.html e cliccare su " Scegli file ". Selezionare il file dal computer che si desidera da caricare . Fai clic su " Carica file. " Il software salva nel database e quindi visualizza l'immagine a voi nel formato che avete richiesto. <br> <br> <div class=ad2><script language='javascript' src='/ad/201310/4.js'></script></div> </div> </td> </tr> </table> <table width="95%" height="1" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#DEE7EE"> <tr> <td></td> </tr> </table> <table width="100%" height="7" border="0" cellpadding="0" cellspacing="0"> <tr> <td></td> </tr> </table> <table width="91%" height="52" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="51%"><p>Previous : <a class='LinkPrevArticle' href='/Programmazione/php-mysql-programming/91907.html' >Come ottenere script PHP Up & Running With Dreamweaver CS3 </a></li></p></td> </tr> <tr> <td width="49%"> next : <a class='LinkNextArticle' href='/Programmazione/php-mysql-programming/91909.html' >Come creare un Tag in PHP </a></li></td> </tr> </table></td> </tr> </table> <table width="100%" height="7" border="0" cellpadding="0" cellspacing="0"> <tr> <td></td> </tr> </table> <table width="770" height="246" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="375" height="246" valign="top"><table width="380" border="0" cellpadding="0" cellspacing="0" class="bian"> <tr> <td height="244" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" background="img_dm/danmai_r4_c04 -.jpg" bgcolor="#DBE3EE"> <tr> <td width="4%" height="29"> </td> <td width="96%" class="lan_lm"> Articoli Correlati </td> </tr> </table> <table width="95%" height="209" border="0" align="center" cellpadding="0" cellspacing="4"> <tr> <td height="201"><table width="100%" cellpadding="0" cellspacing="0"><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/php-mysql-programming/91801.html" title="Come creare una tabella da un'altra tabella in MySQL " target="_self">Come creare una tabella da un'altra tabella in MySQL </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/php-mysql-programming/91638.html" title="Perché non MySQL predefinito in UTF-8 ? " target="_self">Perché non MySQL predefinito in UTF-8 ? </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/php-mysql-programming/92180.html" title="Come modificare la porta SMTP in PHP " target="_self">Come modificare la porta SMTP in PHP </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/php-mysql-programming/92039.html" title="Come caricare script manualmente su MySQL " target="_self">Come caricare script manualmente su MySQL </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/php-mysql-programming/91656.html" title="Alpha Numeric PHP controllare " target="_self">Alpha Numeric PHP controllare </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/php-mysql-programming/91924.html" title="Come installare e configurare MySQL 5.0.77.Tar " target="_self">Come installare e configurare MySQL 5.0.77.Tar </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/php-mysql-programming/91881.html" title="Come ospitare PHP & MySQL applicazioni su Windows " target="_self">Come ospitare PHP & MySQL applicazioni su Windows </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/php-mysql-programming/93170.html" title="Come connettersi al server MySQL " target="_self">Come connettersi al server MySQL </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/php-mysql-programming/93023.html" title="Come creare un modello per una pagina PHP " target="_self">Come creare un modello per una pagina PHP </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/php-mysql-programming/91459.html" title="Errore di analisi in PHP " target="_self">Errore di analisi in PHP </a></td></tr><tr></tr></table></td> </tr> </table></td> </tr> </table></td> <td width="20" valign="top"></td> <td width="375" valign="top"><table width="380" border="0" cellpadding="0" cellspacing="0" class="bian"> <tr> <td height="244" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" background="img_dm/danmai_r4_c04 -.jpg" bgcolor="#DBE3EE"> <tr> <td width="4%" height="29"> </td> <td width="96%" class="lan_lm">Articoli in evidenza </td> </tr> </table> <table width="95%" height="207" border="0" align="center" cellpadding="0" cellspacing="4"> <tr> <td height="199"><table width="100%" cellpadding="0" cellspacing="0"><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/java-programming/90389.html" title="Come chiudere tutte le finestre aperte del browser con Java " target="_self">Come chiudere tutte le finestre aperte del browser con …</a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/java-programming/89280.html" title="Che cosa è Java Metadata " target="_self">Che cosa è Java Metadata </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/visual-basics-programming/94833.html" title="Come connettersi al database Oracle su Vb.Net OLEDB " target="_self">Come connettersi al database Oracle su Vb.Net OLEDB </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/java-programming/89425.html" title="Come prova di INT con Groovy Test " target="_self">Come prova di INT con Groovy Test </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/computer-programming-languages/87633.html" title="Come aggiungere un riquadro per DataGrid C " target="_self">Come aggiungere un riquadro per DataGrid C </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/computer-programming-languages/87535.html" title="Come Bloccare lo sfondo in SMF " target="_self">Come Bloccare lo sfondo in SMF </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/visual-basics-programming/96185.html" title="Come chiamare stored procedure in Visual Basic " target="_self">Come chiamare stored procedure in Visual Basic </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/computer-programming-languages/87882.html" title="Motivi per la scrittura di un loop infinito " target="_self">Motivi per la scrittura di un loop infinito </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/visual-basics-programming/95001.html" title="Come installare VB script con Stampanti " target="_self">Come installare VB script con Stampanti </a></td></tr><tr><td width="10" valign="top" class="">·</td><td class=""><a class="" href="/Programmazione/visual-basics-programming/95676.html" title="Come accedere a più origini dati " target="_self">Come accedere a più origini dati </a></td></tr><tr></tr></table></td> </tr> </table></td> </tr> </table></td> </tr> </table></td> </tr> </table> <table width="980" height="8" border="0" cellpadding="0" cellspacing="0"> <tr> <td></td> </tr> </table> <table border=0 cellSpacing=0 cellPadding=0 width=980 bgColor=#36506e height=90> <tr> <td class=bs height=90 align=middle>Copyright © Conoscenza Informatica http://it.wingwit.com <script language='javascript' src='/ad/201310/1.js'></script></td> </tr> </table> </div> </body> </html>