Re: Image Fields and PHP...

From: Date: Wed, 16 Jan 2002 20:17:19 +0000
Subject: Re: Image Fields and PHP...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-80811@lists.php.net to get a copy of this message
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 "<br><br><br><div align='center'>"; print "<table width='400' border=0 cellpadding=2>" ; print "<tr><td align='left'>" ; print "<font color='#ffffff' face='verdana'><h4>" . "Welcome back " . $firstname . "</h4></font>"; print "</td></tr>"; print "<tr><td 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'> <P><font color='#ffffff' face='verdana' size=1>Upload Photo:</font><input 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.</font><br><br><br>" ; } else { print "<font face='Verdana, Arial, Helvetica, sans-serif' color='#663399'>Error encountered during resume upload process.</font><br>"; } $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" <gonzalze@mail.slh.wisc.edu> wrote in message news:816EFCC70BCAD411B44D0090278F1841051090@slhmailehd.slh.wisc.edu... > 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

« previous php.general (#80811) next »