|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
In case anybody is interested, here is the steps needed to upload a picture to a server, save it in a mysql database, and then have it recalled for displaying on html based web pages:
Here is what you will need: A) Perl 5 B) CGI.pm - thanks to Lincoln Stein C) HTML D) MYSQL or some other database E) perhaps Unix admin priveleges This is broken into 2 parts - submitting a picture, displaying a picture. PART 1 ------------------------------------------------------------------------ 1. Add the input statement to your html page: (this will use the type=file to prompt a file input dialog box) ... <INPUT name=piccie type=file class=inputimage style="HEIGHT: 22px; WIDTH: 192px"> 2. From the same web page , we will call the script (ie savepicture.pl) to save the paramater named piccie (see above). we need to add the all important enctype to the <form> tag (or no pictures, people !) ... <form name="itemsadd" action="/cgi-bin/bb/savepicture.pl" method="post" enctype="multipart/form-data"> 3. Open up the 'savepicture.pl' script ... you should do a few things here: We need to take the pointer from the file parameter sent us via input and take that pointer and start saving that data from your computer to your server - aka uploading. In this case the input parameter is called "piccie". So lets save the file, give it a name and location on your server. You will need to change the directory write priveleges for users called 'nobody' , so you need to chmod the directory ... chmod 777 storedpicturedirectory. (note the priveleges will have to be the admin's call- as 777 is way to much , but for simplicity and debuggin sake, lets carry on...) 4. LETS write the file to the server: In the savepicture.pl script, be sure to include these directives... $dirout= "/home/httpd/html/mydir/images"; #this is where we will actually write the file $htmldirout = "/mydir/images"; # this is where we tell the database to find the image for retrieval $filename = $q->param('piccie'); # lets get the file from our html page (where we called this script from ) # write the file out to the server print "Content-type: text/html\n\n"; open (OUTFILE, ">$dirout/$filename"); while ($bytesread=read($filename,$buffer,1024)) { print OUTFILE $buffer; } close $filename; my $finalfile = $htmldirout . "/" . $fileout; 5. SAVE THE $finalfile field to your mysql database (or other database) - save this info to varchar type field. For purposes of use, $finalfile will be a different name than dirout (server dir), as when retrieving the file, you will be retrieving from a /home/httpd/html/mydir/images directory. Thus you might want to call the file /mydir/mypicture. Right ! OK Your done the input side, you have uploaded the file, saved it to the server (preferably in the wwwdocs dir - (ie /home/httpd/html/ ) and and also written the path + filename to a varchar field in your database . PART II - Displaying it back to the web page. You want to create a perl script to output your record ,ie using CGI.pm , etc... 1 Retrieve the picture url from your database ... In this example I have retrieved the name of the image from a mysql recordset , -- ie. returned a record set into any array ; thus the image file name is contained in $retarray->[0][7] array. here is a sample return from a mysql dbi call, containing my picture link or url ... $retarray = rset->ReturnManyRows("select category, item, description, price, reserve, durationof,piccie from auctionitem where aa = " . "'" . $iid . "%'"); 2) In your show picture script, print the IMG : Here is some sample syntax containing the image link or url to your server's image directory... This will display the image on the html page... print "<IMG NAME=". '"' . "bbb" . '"' . " SRC=" . '"' . $retarray->[0][7] . '"' . ">"; THATS IT, hope it works ! byron |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > uploading pictures and retrieving them |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|