[PHP] Re: Image Fields and PHP...

2002-01-17 Thread Lerp

Hi again, I guess one really good reason  for not storing images directly in
a db table is performance. When you store a blob in a table it affects the
whole database's performance. It slows it down, that's why the most common
method is to store the images in a dir on the webserver and store only the
path to the image in the databse field. That code I posted  in the previous
will allow uploading of an image to a directory on the server, store the
path to the image in the correct record for retrieval at a later point. It
also retrieves an image for a particular record.

HTH Joe :)


Zara E Gonzalez [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Not sure if this is off topic for this list or not, but thought I would
try...

 I have a Linux server running Redhat 7.0, PHP 4.1.1, and freetds 0.53. My
Linux
 server connects to a Win2k server running MSSQL 2000.

 Everything works wonderfully, except, I have an image field in one of my
tables
 and I can't seem to find a way to pull it out without having PHP
completely
 freak out. (i.e. I get no error message at all just page cannot be
displayed)

 So I'm wondering, can you pull image fields out with PHP?

 If so, I'm guessing my limitation is freetds. If not, is there any way to
pull
 an image out of a database using php? (i.e. store it in a different type
of
 field not image.)

 Any help is appreciated,

 Thanks,

 Zara



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: Image Fields and PHP...

2002-01-16 Thread Lerp



Hi Zara, are you storing a path to the images in your db? Or the actual
image? It's recommended that you stay away from storing actual images in the
db. If you are
storing a path the code below might help you out. It select a firstname, and
an image according to an id. You'll have to change the youridentityfield
and
youridentity values to suit your needs.  If you are looking for an image
upload script



# display image from db
#
#connect to db
$connectionToDBid = odbc_connect(ceo34deesnr43ipits, joeyscode,
joeyscode);


// sql statement
$sqlb = SELECT imagepath, firstname FROM IMAGES WHERE youridentityfield =
. $youridentity;

# execute the query
$resultset = odbc_do($connectionToDBid, $sqlb);

$image = odbc_result($resultset,1);
$firstname = odbc_result($resultset,2);

print brbrbrdiv align='center';
print table width='400' border=0 cellpadding=2 ;
print trtd align='left' ;
print  font color='#ff' face='verdana'h4 . Welcome back  .
$firstname . /h4/font;
print /td/tr;
print trtd align='center' ;
print img src=' . $image.'  align='center' border='0'br;
print /td/tr;
print /table;

# close the db connection here

# end of display image from db
#



#photo upload form


Here's a common form that allows you to upload a file (say an image) to the
db

form action='upload.php' method='post' enctype='multipart/form-data'
input type='hidden' name='MAX_FILE_SIZE' value='102400'
Pfont color='#ff' face='verdana' size=1Upload Photo:/fontinput
type='file' name='userfile'input type='submit'
value='Upload!!!'/form/p

end of photo upload form
##


start of upload process to db

?php

# $userfile is the file being uploaded


# print $userfile . BR;
# print $userfile_name . BR;

#use a time stamp to uniquely name the image before storing in db to prevent
two files with the same name

$timestamp = time();
$userfile_name = $timestamp.$userfile_name ;

// copy the file being posted -- remember to escape backslashes!!!
if(copy($userfile, /ez/codesnipits/consultant/tempimages/.
$userfile_name)){
print font face='Verdana, Arial, Helvetica, sans-serif' color='#663399'
size='2'Your picture has been uploaded successfully and has been made
available for
online users to view./fontbrbrbr ;
}
else
{
print font face='Verdana, Arial, Helvetica, sans-serif'
color='#663399'Error encountered during resume upload process./fontbr;
}

$patharola = tempimages/. $userfile_name;

// insert path into database here
# connect to db
$connectionToDBid = odbc_connect(cdefc5onwesulertt, joeyscon,
joeyscon);

session_register(consultantid);
$consultantid = $consultantid;

# create query statement -- update image field in db using path
$sqlr = UPDATE CONSULTANT SET image= '$patharola' WHERE consultantid= .
$consultantid;
# execute the sql statement (query) on the connection made
$resultset = odbc_do($connectionToDBid, $sqlr);


?

end of image to db process
##


Hope this helps you out :)

Cheers Joe :)



Zara E Gonzalez [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Not sure if this is off topic for this list or not, but thought I would
try...

 I have a Linux server running Redhat 7.0, PHP 4.1.1, and freetds 0.53. My
Linux
 server connects to a Win2k server running MSSQL 2000.

 Everything works wonderfully, except, I have an image field in one of my
tables
 and I can't seem to find a way to pull it out without having PHP
completely
 freak out. (i.e. I get no error message at all just page cannot be
displayed)

 So I'm wondering, can you pull image fields out with PHP?

 If so, I'm guessing my limitation is freetds. If not, is there any way to
pull
 an image out of a database using php? (i.e. store it in a different type
of
 field not image.)

 Any help is appreciated,

 Thanks,

 Zara



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Re: Image Fields and PHP...

2002-01-16 Thread Gonzalez, Zara E

Joe (And/Or others),

We are storing the actual images in the DB. We did not want our pictures to be
on our webserver. Instead we felt it would be better to keep them on the
database server. In order to do this, they had to be stored in the database
itself since the database server is not accesible by the web. (I.e. the only way
to get stuff off of it via the web is to pull it out through the DB connection)

Now, You say that it is not recommended that we store our images in our
database, can you give me a reasons why?

Thanks,

Zara
-Original Message-
From: Lerp [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, January 16, 2002 2:17 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: Image Fields and PHP...




Hi Zara, are you storing a path to the images in your db? Or the actual image?
It's recommended that you stay away from storing actual images in the db. If you
are storing a path the code below might help you out. It select a firstname, and
an image according to an id. You'll have to change the youridentityfield and
youridentity values to suit your needs.  If you are looking for an image
upload script



# display image from db
#
#connect to db
$connectionToDBid = odbc_connect(ceo34deesnr43ipits, joeyscode,
joeyscode);


// sql statement
$sqlb = SELECT imagepath, firstname FROM IMAGES WHERE youridentityfield = .
$youridentity;

# execute the query
$resultset = odbc_do($connectionToDBid, $sqlb);

$image = odbc_result($resultset,1);
$firstname = odbc_result($resultset,2);

print brbrbrdiv align='center';
print table width='400' border=0 cellpadding=2 ;
print trtd align='left' ;
print  font color='#ff' face='verdana'h4 . Welcome back  .
$firstname . /h4/font; print /td/tr; print trtd align='center'
; print img src=' . $image.'  align='center' border='0'br; print
/td/tr; print /table;

# close the db connection here

# end of display image from db
#



#photo upload form


Here's a common form that allows you to upload a file (say an image) to the db

form action='upload.php' method='post' enctype='multipart/form-data' input
type='hidden' name='MAX_FILE_SIZE' value='102400' Pfont color='#ff'
face='verdana' size=1Upload Photo:/fontinput type='file'
name='userfile'input type='submit' value='Upload!!!'/form/p

end of photo upload form
##


start of upload process to db

?php

# $userfile is the file being uploaded


# print $userfile . BR;
# print $userfile_name . BR;

#use a time stamp to uniquely name the image before storing in db to prevent two
files with the same name

$timestamp = time();
$userfile_name = $timestamp.$userfile_name ;

// copy the file being posted -- remember to escape backslashes!!!
if(copy($userfile, /ez/codesnipits/consultant/tempimages/.
$userfile_name)){
print font face='Verdana, Arial, Helvetica, sans-serif' color='#663399'
size='2'Your picture has been uploaded successfully and has been made available
for online users to view./fontbrbrbr ; } else { print font
face='Verdana, Arial, Helvetica, sans-serif' color='#663399'Error encountered
during resume upload process./fontbr; }

$patharola = tempimages/. $userfile_name;

// insert path into database here
# connect to db
$connectionToDBid = odbc_connect(cdefc5onwesulertt, joeyscon, joeyscon);

session_register(consultantid);
$consultantid = $consultantid;

# create query statement -- update image field in db using path $sqlr = UPDATE
CONSULTANT SET image= '$patharola' WHERE consultantid= . $consultantid; #
execute the sql statement (query) on the connection made $resultset =
odbc_do($connectionToDBid, $sqlr);


?

end of image to db process
##


Hope this helps you out :)

Cheers Joe :)



Zara E Gonzalez [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Not sure if this is off topic for this list or not, but thought I 
 would
try...

 I have a Linux server running Redhat 7.0, PHP 4.1.1, and freetds 0.53. 
 My
Linux
 server connects to a Win2k server running MSSQL 2000.

 Everything works wonderfully, except, I have an image field in one of 
 my
tables
 and I can't seem to find a way to pull it out without having PHP
completely
 freak out. (i.e. I get no error message at all just page cannot be
displayed)

 So I'm wondering, can you pull image fields out with PHP?

 If so, I'm guessing my limitation is freetds. If not, is there any way 
 to
pull
 an image out of a database using php? (i.e. store it in a different 
 type
of
 field not image.)

 

Re: [PHP] Re: Image Fields and PHP...

2002-01-16 Thread Jason Bell

It basically comes down to speed. While there is nothing Technicaly wrong
with storing the images in the database, accessing the images will become
slower as the database gets larger, than if the files were stored on the
filesystem. Whether or not this degredation of performance is acceptable or
not is up to you, but... if you still want to pull an image directly from
the database, try the following method. Please note that you must have the
image type stored in the database as well.

Create a seperate PHP script called getimg.php:

/* Begin getpic.php */
?php
if($id) {
$dbhost = ;  /* MySQL Server */
$dbuser = ; /* MySQL UserName */
$dbpass = ;   /* MySQL Password */
$dbname = ; /* MySQL Database */
$db = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname,$db);
$query = select image,type from images where id=$id;
$result = mysql_query($query);
$data = mysql_result($result,0,image);
$type = mysql_result($result,0,type);
Header( Content-type: $type);
echo $data;
};
?

/* End getpic.php

Now that you have this, when you want to display a picture, call getpic.php
in your img tag like so:

IMG SRC=getpic.php?id=12 (obviously, this gets the picture with ID 12
from the database. )


There are probably more elegant ways of doing this, but it works.  :)

- Original Message -
From: Gonzalez, Zara E [EMAIL PROTECTED]
To: 'Lerp' [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Wednesday, January 16, 2002 1:52 PM
Subject: RE: [PHP] Re: Image Fields and PHP...


 Joe (And/Or others),

 We are storing the actual images in the DB. We did not want our pictures
to be
 on our webserver. Instead we felt it would be better to keep them on the
 database server. In order to do this, they had to be stored in the
database
 itself since the database server is not accesible by the web. (I.e. the
only way
 to get stuff off of it via the web is to pull it out through the DB
connection)

 Now, You say that it is not recommended that we store our images in our
 database, can you give me a reasons why?

 Thanks,

 Zara



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Re: Image Fields and PHP...

2002-01-16 Thread Gonzalez, Zara E

Actually, I can't do that. Which is the whole problem I'm having. PHP fails when
I try to pull the image field out of my database. After talking to others I
thought it might be the @@textsize variable in MSSQL unfortunately setting it to
a lower value did not solve my problem. I have recently spoken to another person
who is having the same problem as I am and it appears to be a problem with one
or all of the programs I am using. (MSSQL, PHP, and FreeTDS)

I guess I'll have to change how my system is set up after all.




-Original Message-
From: Jason Bell [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, January 16, 2002 4:17 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Re: Image Fields and PHP...


It basically comes down to speed. While there is nothing Technicaly wrong with
storing the images in the database, accessing the images will become slower as
the database gets larger, than if the files were stored on the filesystem.
Whether or not this degredation of performance is acceptable or not is up to
you, but... if you still want to pull an image directly from the database, try
the following method. Please note that you must have the image type stored in
the database as well.

Create a seperate PHP script called getimg.php:

/* Begin getpic.php */
?php
if($id) {
$dbhost = ;  /* MySQL Server */
$dbuser = ; /* MySQL UserName */
$dbpass = ;   /* MySQL Password */
$dbname = ; /* MySQL Database */
$db = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname,$db);
$query = select image,type from images where id=$id;
$result = mysql_query($query);
$data = mysql_result($result,0,image);
$type = mysql_result($result,0,type);
Header( Content-type: $type);
echo $data;
};
?

/* End getpic.php

Now that you have this, when you want to display a picture, call getpic.php in
your img tag like so:

IMG SRC=getpic.php?id=12 (obviously, this gets the picture with ID 12
from the database. )


There are probably more elegant ways of doing this, but it works.  :)

- Original Message -
From: Gonzalez, Zara E [EMAIL PROTECTED]
To: 'Lerp' [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Wednesday, January 16, 2002 1:52 PM
Subject: RE: [PHP] Re: Image Fields and PHP...


 Joe (And/Or others),

 We are storing the actual images in the DB. We did not want our 
 pictures
to be
 on our webserver. Instead we felt it would be better to keep them on 
 the database server. In order to do this, they had to be stored in the
database
 itself since the database server is not accesible by the web. (I.e. 
 the
only way
 to get stuff off of it via the web is to pull it out through the DB
connection)

 Now, You say that it is not recommended that we store our images in 
 our database, can you give me a reasons why?

 Thanks,

 Zara



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED] To contact the
list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]