blob类型字段,以前网上有一篇文章讲的,搜索一下吧
不过最好还是直接存放在磁盘上好,不要浪费数据库

解决方案 »

  1.   

    这有一篇,讲mysql中存储图象的,我估计oracle中也差不多
    * Image Database Functions by: J. Patrick Ryans [email protected] July 1998 The following are provided niether with copyright or warranty.  I do not 
    believe that any of the code in this file is copyrighted by anyone else, but 
    if it is, please let me know. I gathered these functions from a larger php3 project to manage a 
    large and dynamic web site by keeping all html, images, and other file 
    contained in a MySQL database.  I couldn't find one single example that 
    explained how to insert binary images into a database and then extract them 
    and display it to the browser. The two major functions needed to load and display images are shown below, 
    but I have left out many details such as how to connect to the database, 
    how to use html forms, etc.  That information can be picked up from a number 
    of places.  I.e. check out: http://webdev.berber.co.il 
    for examples of how to connect to a database, and http://liquid-sky.media.mit.edu/file_upload.html 
    for how to use forms to upload files My database has a table for storing binary data such as images and other 
    types.  The schema is as follows: # 
    # Table structure for table 'binary' 

    CREATE TABLE binary ( 
      id int(11) DEFAULT '0' NOT NULL auto_increment, 
      title varchar(200) DEFAULT '' NOT NULL, 
      auth_id varchar(16) DEFAULT '' NOT NULL, 
      description varchar(200), 
      category varchar(50) DEFAULT '' NOT NULL, 
      body longblob, 
      cr_date date, 
      datestamp timestamp(14), 
      type varchar(50) DEFAULT '' NOT NULL, 
      KEY category (category), 
      KEY title (title), 
      KEY auth_id (auth_id), 
      PRIMARY KEY (id) 
    ); 
    */ 
    /* Loading binary files into the database There isn't room here to show the html forms, how to connect to the 
    database and the code for uploading the file into the database, so I'm 
    going to have to be a little terse here.  I'm going to assume that you 
    know how to use forms to upload files, and I'm going to assume that you 
    know how to connect to your database which has a table of structure 
    similar to the schema shown above. This script is expecting to recieve the following variables from the form: $title          // the title of the file 
    $auth_id        // the id name of the author -  field is specific to my needs 
    $desc           // a short description 
    $cat            // category, for organization purposes. 
    $type           // mime type - something like "image/gif" Be forewarned, error checking is very minimal in this routine, you will 
    probably want to do some more sanity checking in a production environment. 
    In my forms, I query the database to present a select list of valid author 
    ids and mime types. 
    */ 
    <? // load.php3         include "admin_connect.ini"; // connect as a user with insert auth. 
            include "main_h.inc";        // an html header for the page 
            echo "<center>\n"; 
            $date = date("Y-m-d"); 
            //$title = htmlentities($title);  // you may want to clean up the input 
                                              // with statements like this.         // Check to see if a file was included in the input="file" tag         if(chop($fileinput)!=""){                 // $fileinput should point to a temp file on the server 
                    // which contains the uploaded image. so we will prepare 
                    // the file for upload with addslashes and form an sql 
                    // statement to do the load into the database.                 $image = addslashes(fread(fopen($fileinput,"r"), 1000000)); 
                    $SQL = "Insert Into $PhotoTable  
    (title,auth_id,description,category,body,cr_date,type) values ('$title', 
    '$auth_id', '$desc', '$cat', '$image','$date','$type')";                 // now we can delete the temp file 
                    unlink($fileinput); 
            } 
            else{ 
                    echo "no file entered on form"; 
                    exit; 
            }         $Result = mysql_db_query ( $DB, $SQL );         if($Result==0){ 
                    echo "unsuccessful add"; 
            } 
            else{ 
                    echo "successful add"; 
            } 
            include "main_f.inc"; 
    ?> /* Displaying an image from the database. This is a very simple way to display the image that was loaded in the above 
    script.  In this case we will query the image by title, but it would be 
    a simple matter to add other queries. You must have the mime type for the image stored in the record with the 
    image data.  As per the schema above, the mime type is stored in the 'type' 
    field. Be careful that any includes and initialization files do not send anything 
    to the browser. You want the Header("Content-type: $type"); to be the first 
    line served. To use the following script to display an image, use an image tag similar 
    to the following: <img src="image.php3?title=myimage.gif"> */ 
    <? // image.php3         // connect to database with select access 
            include "user_connect.ini"; 
            $SQL = "select body,type from $PhotoTable where title='$title'"; 
            $Show = mysql ( $hDB, $hSQL ); 
            $Rows = mysql_num_rows($hShow);         if($Rows<1){ 
                    // no image matches this query 
            } 
            else{ 
                    // at least one image has this title 
                    $getPhoto = mysql_fetch_object($Show);                 // we need to determine the mime type 
                    $Type = $getPhoto->type;                 // and send the correct header to the browser 
                    Header("Content-type: $Type");                 // now send the image 
                    $Body = $getPhoto->body; 
                    echo $Body; 
                    flush(); 
            } 
    ?> 
      

  2.   

    btw:这篇文章我自己还没看:)太困了,该睡觉了
      

  3.   

    整理:
    存入图片
    <form name="form1" method="post" action="<?echo $path_info?>" enctype="multipart/form-data">
      <p>
        <input type="text" name="id">
      </p>
      <p> 
        <input type="text" name="title">
      </p>
      <p> 
        <input type="file" name="fileinput">
      </p>
      <p>&nbsp;<input type="submit" name="Submit" value="Submit">
    </p>
    </form>
    <?
    mysql_connect("localhost","root","123") or die("connect error");
    mysql_select_db("yujin");
    if($Submit)
    {
     /*================================================================
       开启档案或者 URL。
       语法: int fopen(string filename, string mode);'r' 开档方式为唯读,档案指标指到开始处。 
        
       位元组的方式读取档案。
       语法:string fread(int fp, int length);
         
       字串加入斜线。
       语法: string addslashes(string str);
    ==================================================================*/
       $image = addslashes(fread(fopen($fileinput,"r"), 1000000)); 

       $SQL = "Insert Into binary1 (id,title,body) values ('$id','$title','$image')"; 

      /*=================================
         删除档案。
         语法: int unlink(string filename);
        =================================*/
        unlink($fileinput);     $error=mysql_query($SQL);
      }
      ?>显示图片
    <?
     $db=mysql_connect("localhost","root","123") or die("connect error");
     mysql_select_db("yujin");  $SQL="select * from binary1 where id='3'";
      $Show = mysql_query($SQL);  $getPhoto = mysql_fetch_object($Show); 
      
      $Type = $getPhoto->type; 
      // and send the correct header to the browser 
      Header("Content-type: $Type");   // now send the image 
      $Body = $getPhoto->body; 
      echo $Body;   /*
      清出输出缓冲区。
      语法: void flush(void);
      */
      flush(); 
    ?>
      

  4.   

    写blob$sql = "insert into mypic(id, name,BINARYDATA)  values(mypic_id.nextval, '$name',  EMPTY_BLOB()) RETURNING BINARYDATA into :BINARYDATA";
    $stmt = @OCIParse($conn, $sql);
    /** 生成一个本地LOB对象的描述符 */
    $lob = @OCINewDescriptor($conn, OCI_D_LOB);
    @OCIBindByName($stmt, ':BINARYDATA', &$lob, -1, OCI_B_BLOB);
    @OCIExecute($stmt);
    /** 载入文件 */
    $lob->savefile($bfile);
    @OCIFreeDesc($lob);
    @OCIFreeStatement($stmt);
      

  5.   

    读blob$sql = "select id ,name, binarydata from mypic where id=1";
    $stmt = @OCIParse($conn, $sql);
    @OCIExecute($stmt);
    @OCIFetchInto($stmt, &$info, OCI_ASSOC);
    echo "ID=>" . $info['ID'];
    echo "<br>Name=>" . $info['NAME'];
    echo "<br>Content=>" . $info['BINARYDATA']->load();
    @OCIFreeStatement($stmt);
      

  6.   

    读blob$sql = "select id ,name, binarydata from mypic where id=1";
    $stmt = @OCIParse($conn, $sql);
    @OCIExecute($stmt);
    @OCIFetchInto($stmt, &$info, OCI_ASSOC);
    echo "ID=>" . $info['ID'];
    echo "<br>Name=>" . $info['NAME'];
    echo "<br>Content=>" . $info['BINARYDATA']->load();
    @OCIFreeStatement($stmt);