Re: IMAGES IN DB
| From: | Donatas | Date: | Sun, 08 Feb 2004 10:58:34 +0000 |
| Subject: | Re: IMAGES IN DB | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-22764@lists.php.net to get a copy of this message | ||
Heh I never thought I'd say this to anyone... but thank you for being so lazy. I wanted to know this long time ago but now I googled and found a great tutorial on this! http://codewalkers.com/tutorialpdfs/tutorial35.pdf
For all lazy ones asking for help in the future... GOOGLE YOU BITCHES, GOOGLE! If you won't find the answer in 10 minutes, ask :)
/Donny
zanzamarr wrote:
Hello everyone! I'm building a site about all the states of the world..... in the DB (MySql), I'm going to insert many dates: id, country,a, lot,of,informations,about,the,country and the image of the map of the country and pf the flag. The code I use to put into my db the image is this (see under) and it works...but when I try to display the image I get this string: What's wrong?????????????????? GIF89a@???,@?ǂ??ӓ???H???*\Ȱ?Ç#J?H??ŋ+?QǁI?dI9?Lɒ䊗-?ʼ93&͛6sY?'N?:{ ?F?]Z?iD?&??D???իX?j݊?+B?RMR?ٳhӒ?䘵p㊝K?+۶ޖ??_?w۪?????W?#K?L??eˎժ?ʸ?竛?bM?Ɗ??딫??sӶ?x6s "Ƥ?PF㔔Vi啘a?\v?֖^?)fV?i晔??暬ڸ_?pƉݛrֹ??vƢ?r♧]&ꖧ?ҕ(r??Wh_?Φ⣐F i??E??sHZڥ?譹?? ???a??詉?jx???.??敫??H????Hk??ޚ뗻?y豂ފఇ?*??????ʬAv ?M{]?x??굂"??Bm?䌯???b?ѻ/a?ƻo???\?N毲窯?Ú &1?권w챇 ?,l?첋0Ǭ?˲֬鬎<Ƕsπ{?6tш?s%?J~>M?? I??~U???]??u?m6դ?ͣ?M?m(ۮǭܲם֒v獦ݺ?߾>?jm?핾???W???.9ᔓ$??yp?댹糆ަ䤯Ι?蟫^!륒깩?엒.߃Mٗk??ſ2F?R˻ż?Ք??ߌ??Կg;?rol?y???Ϙ?͢?K?Ҳ???^???.q?K?ᘐuީՇX@6PP?(X?~˂?nᏀ'? ?0\tųå???ˡƤ??PIJ?ȣ!i yP?UḮzռfՐ}5!a?)׃?3???????˪_\ѤَV?k?:+C???啤ahZ??V??]??䷘ƿf???!- [?֗?rM?Սg?꛰ƶ? .S??V?Hp?ȝt/[[ۦT?[ .rdkނV?x= wW7]Ϻ???kٶ???Ԫ.sg?W????ޓ???֚F(N??????'Lኛx2 ΰ??ɡï?\<ޖɘ%%??祣?1ĻݢոS6^???b"?H+?H?,dw??b???wF?c1?_ar??\d"???k?Rֲ??ܥ&??G?e'sٖů&??*紟كxγ??!?ARDIV 5.0 ! ; --------------------------------------------------------------------------------------Code to insert the image in the DB------------------------------------------------------------------------- <?Php if(!isset($_POST)) $_POST = $HTTP_POST_VARS; $self = isset($_SERVER) ? $_SERVER["PHP_SELF"] : $HTTP_SERVER_VARS["PHP_SELF"]; if($_POST["invia"]) { //Definisco le variabili $host = "localhost"; $user = "bubusettete"; $password = ""; $nomedb = "schedestati"; $tabella = "stati"; $stato = "Italia"; // Mi connetto a MySql e seleziono il database $connessione = mysql_connect($host,$user,$password) or die ("Non mi riesco a connettere al database"); mysql_select_db($nomedb, $connessione) or die ("Non riesco a selezionare il db specificato"); $data = addslashes(fread(fopen($_FILES["file_binario"]["tmp_name"], "rb"), $_FILES["file_binario"]["size"])); $nomefile = $_FILES["file_binario"]["name"]; $sizefile = $_FILES["file_binario"]["size"]; $typefile = $_FILES["file_binario"]["type"]; $result = @mysql_query(" UPDATE $tabella SET dati_binari_cartina = \"$data\", nome_carta_stato = \"$nomefile\", dimensione_carta_stato = \"$sizefile\", tipo_carta_stato = \"$typefile\" WHERE stato ='$stato' ") or die("Query di inserimento fallita !"); echo "Il file " . basename($_FILES["file_binario"]["name"]) . " è stato correttamente inserito nel Database."; @mysql_close(); } else {echo "<html> <head> <title>Form per l'inserimento</title> </head> <body> <div align=\"center\"> <table> <form action=\"$self\" method=\"POST\" enctype=\"multipart/form-data\"> <tr> <td>File</td> <td><input type=\"file\" name=\"file_binario\" size=\"40\"></td> </tr> <tr> <td colspan=\"2\" valign=\"bottom\" align=\"center\" height=\"30\"> <input type=\"submit\" value=\"Invia il file\" name=\"invia\"> </td> </tr></form> </table></div></body></html> ";} ?> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------Code to diplay the image------------------------------------------------------------------------------------ <? // -------------------------------- Modulo per la visualizzazione dei dati di un database -------------------------------// $host = "localhost"; $user = "bubusettete"; $password = ""; $nomedb = "schedestati"; $tabella = "stati"; $stato = "Italia"; // Mi connetto a MySql e seleziono il database $connessione = mysql_connect($host,$user,$password) or die ("Non mi riesco a connettere al database"); mysql_select_db($nomedb, $connessione) or die ("Non riesco a selezionare il db specificato"); // Query SQL per selezionare tutti i record della tabella $sql = " SELECT * FROM $tabella WHERE stato='$stato' "; // Inserisco in un array tutte le voci del record che ha quel nome di stato $elencodati = mysql_query($sql,$connessione) or die ("Impossibile avviare la query"); while($riga = mysql_fetch_array($elencodati)){ $stato = $riga['stato']; $lingua = $riga['lingua']; $area = $riga['area']; $id = $riga['id']; $immagine = $riga['dati_binari_cartina']; $tipo = $riga['tipo_carta_stato']; } // Stampo le voci dell'array echo "$stato <br />"; echo "$lingua <br />"; echo $immagine; ?> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------