php-windows Digest 9 Feb 2004 03:03:52 -0000 Issue 2113
Topics (messages 22764 through 22773):
Re: IMAGES IN DB
22764 by: Donatas
22765 by: Svensson, B.A.T. (HKG)
22766 by: John Ellingsworth
22767 by: Shannon Eric Peevey
22768 by: Svensson, B.A.T. (HKG)
22769 by: Shannon Eric Peevey
22770 by: Svensson, B.A.T. (HKG)
22771 by: Shannon Eric Peevey
22772 by: hubo
newbie file script
22773 by: Stephen Rivas Jr
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin 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??????????????????
[EMAIL PROTECTED],@?Ç??Ó???H???*\È?Ã#J?H??Å+?Q`ÇI?dI9?LÉä-?Ê93&Í6sÂY?'N?:{ ?F?]Z?iD?&??D???ÕX?jÝ?+B?RMR?ÙhÓ?äpãK?+ÛÞÝ??_?wÛ?????W?#K?L??eËÕ?Ê?çñ?bM?Æ??ë?î?sÓ?x6ïs "Æ?PFãViåÂa?\v?Ö^?)fV`?iæ??æÚ_?pÆÝrÖ??vÆ?râ]&ê?Ò(r??Wh_?ÎâF i??E??sHZÚ?è?? ???a??è?jx???.??æ??H????Hk??Þë?yèÞà?*??????ÊAv ?M{]?x??ê"??îB×m?ä???ð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;[EMAIL PROTECTED](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;
?>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- End Message ---
--- Begin Message ---
You probaly need to set the content type properly.
A comment on storing binary content in an RDBMS's:
QUESTION: Is it possible to do a SELECT on an image that makes sence.
ANSWER: no!
So, the concensus might be that one rather would like to store
the images as a plain file on the server, and just store a file
pointer in the RDBMS.
-----Original Message-----
From: zanzamarr
To: [EMAIL PROTECTED]
Sent: 2004-02-08 11:11
Subject: [PHP-WIN] IMAGES IN DB
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
--- End Message ---
--- Begin Message ---
In a file called image.php do this:
<?php
ob_start(); // turn output buffering on
// open the database and retrieve the record
$dbh=mysql_connect ("localhost","YOUR_USERNAME_HERE","YOUR_PASS_HERE");
mysql_select_db("YOUR_DBNAME_HERE",$dbh);
$query = "SELECT thumbnail FROM thumbs WHERE thumbid = $thumb";
$result = @ mysql_query ($query, $dbh);
$data = @mysql_fetch_array($result);
$image = $data["thumbnail"];
header("Content-Type: image/jpeg");
echo $image;
ob_end_flush();
?>
Then embed this into an img tag in a DIFFERENT page:
<img src=image.php?thumbid=1>
Thanks,
John Ellingsworth
http://mail.med.upenn.edu/~jellings/
AIM: vc2000support
-----Original Message-----
From: zanzamarr [mailto:[EMAIL PROTECTED]
Sent: Sunday, February 08, 2004 5:11 AM
To: [EMAIL PROTECTED]
Subject: [PHP-WIN] IMAGES IN DB
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??????????????????
[EMAIL
PROTECTED],@?Ç??Ó???H???*\È?Ã#J?H??Å+?Q`ÇI?dI9?LÉä-?Ê93&Í6sÅY?'N?:{
?F?]Z?iD?&??D???ÕX?jÝ?+B?RMR?ÙhÓ?äpãK?+ÛÞÝ??_?wÛ?????W?#K?L??eËÕ?Ê?çñ?bM?Æ??ë?î?sÓ?x6ïs
"Æ?PFãViåËa?\v?Ö^?)fV`?iæ??æÚ_?pÃÝrÖ??vÆ?râ]&ê?Ò(r??Wh_?ÎâF
i??E??sHZÚ?è?? ???a??è?jx???.??æ??H????Hk??Þë?yèÞà?*??????ÊAv
íM{]?x??ê"??îB×míä???ð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;[EMAIL
PROTECTED](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;
?>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- End Message ---
--- Begin Message ---
Svensson, B.A.T. (HKG) wrote:
You probaly need to set the content type properly.
A comment on storing binary content in an RDBMS's:
QUESTION: Is it possible to do a SELECT on an image that makes sence.
ANSWER: no!
that is what metadata is for.
So, the concensus might be that one rather would like to store
the images as a plain file on the server, and just store a file
pointer in the RDBMS.
Ahhh.... The age old question about storing images in the database ;)
There are many a flame war about this in the archives, but I believe
that there are times to store the images in a database. For example,
if portability is your main concern, if your file structure changes
frequently, or is complex enough to make it difficult to manage. The
obvious caveats are: a hit in performance and a very large database.
Just my $0.02 :)
speeves
cws
--- End Message ---
--- Begin Message ---
> Ahhh.... The age old question about storing
> images in the database ;)
I take no stand point for either side, but from a
puristic relational stand point, binary contents
has nothing, what so ever, to in the RDBMS.
This is, of course, only a thumb rule, then of course we
can find good execptions from this. But I think one should
not automatically put everything into the RDBMS, just because
of the sake of things.
> The obvious caveats are: a hit in performance
> and a very large database.
Unless the RDBMS has inplimented file pointers instead of
actually storing a chunk of binary lumps in your RDBMS.
--- End Message ---
--- Begin Message ---
Svensson, B.A.T. (HKG) wrote:
Ahhh.... The age old question about storing
images in the database ;)
I take no stand point for either side, but from a
puristic relational stand point, binary contents
has nothing, what so ever, to in the RDBMS.
Again, that is what metadata is for :)
speeves
cws
--- End Message ---
--- Begin Message ---
>>I take no stand point for either side, but from a
>>puristic relational stand point, binary contents
>>has nothing, what so ever, to in the RDBMS.
>>
>
>Again, that is what metadata is for :)
What do you refer to as meta data in this context?
speeves
cws
--- End Message ---
--- Begin Message ---
Svensson, B.A.T. (HKG) wrote:
I take no stand point for either side, but from a
puristic relational stand point, binary contents
has nothing, what so ever, to in the RDBMS.
Again, that is what metadata is for :)
What do you refer to as meta data in this context?
the information that is used to describe an object that is "binary" in
format. (This is taken from libraries, where they must describe a book,
cd, etc. in such a way that we, as normal humans, can find what we are
looking for :) ) Metadata in our sense, is that information which would
describe our image so that we may search for it... accurately :) (BTW,
XML is an increasingly popular way of doing just this)
I actually agree with you on the point that most images should be stored
on the filesystem, (and the person that started this thread should
probably do that as well). My only point was that databases _can_ be
used as storage/delivery devices in special situations in which the
speed of delivery is outweighed by other factors.
thanks :)
speeves
cws
--- End Message ---
--- Begin Message ---
> A comment on storing binary content in an RDBMS's:
>
> QUESTION: Is it possible to do a SELECT on an image that makes sence.
> ANSWER: no!
>
My answer is: Yes!
Have you never heard about the algorithm to compare and to sort (!) pictures not only
using their meta data but also by analyzing the image data? Ask some people in some
communication agencies. To find a picture just somehow like another is a standard job.
I have seen a lot of demonstrations years ago. Well, they are ORDBMS's. Have a look at:
http://www.ibm.com/software/data/informix/blades/excaliburimage/
Sure, the most important arguement to put images into a database is to eneasy the
handling of these thousands or even much more files...
--- End Message ---
--- Begin Message ---
hey guys - I'm sure this is old school problems but without any environment
variables can you tell me if I'm doing something wrong?? thanks.
I've been working on a listing that you can add titles to - so that I can
add a title and an auto link to the file with the new update. Basically, the
main text goes into one file, and then title and the link to that file
*should* go to listing.html - posted from the top down. Although, every time
I run through it - it overwrites the uppermost title with the new one. All
the older titles stay the same, just the first X chars of the file are
replaced with submitted X title chars. I'm using fopen with r+.
Is there anything about r+ that would not add text to the very beginning of
a file? Should I get the files contents, add to them, and then write back to
the file? Right now I'm just going fopen, fwrite, fclose. Hoping to add text
to the beginning of a file without replacing the current contents.
Script/more info avail if needed. Thanks!
Stephen Rivas Jr
--- End Message ---