将图片从php表格上传到oracle数据库

时间:2014-07-10 11:49:46

标签: php image oracle uploading oracle11gr2

将图像上传到oracle数据库时遇到问题。

这是我的database.php 它从表单中获取值并将其发送到我的数据库。 我的oracle版本是11g。

<meta http-equiv="Content-Language" content="ar-sa">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<?php
session_start();
    include('connection.php');
    /* @var $fname type */
     $fname=$_POST["fname"];
     $sn=$_POST["sn"];
     $gender=$_POST["gender"];
     $email=$_POST["email"];
     $passwd=$_POST["passwd"];
     $unvi=$_POST["unvi"];
     $section=$_POST["section"];
     $dep=$_POST["dep"];
     $phone=$_POST["phone"];
     $tren=$_POST["tren"];
     $hour=$_POST["hour"];
     $period=$_POST["period"];
     $term=$_POST["term"];
     $year=$_POST["year"];


 $allowedExts = array("gif", "jpeg", "jpg", "png","JPG");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/JPG")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 2000000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {


    if (file_exists("student/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "student/" . $_FILES["file"]["name"]);


            $pic= "student/" . $_FILES["file"]["name"];

$insert ="INSERT INTO APPLICATION(NAME,SN,GENDER,PASS,UNVI,DEP,PHONE,TERM,HOUR,PERIOD,TREN,YEAR,EMAIL,SECTION,STATE,PIC)VALUES(:fname,:sn, :gender, :passwd, :unvi, :dep, :phone, :term, :hour, :period, :tren, :year,:email,:section,'Waiting',:pic)";
  $send = oci_parse($conn, $insert);

oci_bind_by_name($send, ':fname', $fname);
oci_bind_by_name($send, ':sn', $sn);
oci_bind_by_name($send, ':gender', $gender);
 oci_bind_by_name($send, ':passwd', $passwd);
 oci_bind_by_name($send, ':unvi', $unvi);
  oci_bind_by_name($send, ':section', $section);
 oci_bind_by_name($send, ':dep', $dep);
 oci_bind_by_name($send, ':phone', $phone);
 oci_bind_by_name($send, ':term', $term);
 oci_bind_by_name($send, ':hour', $hour);
 oci_bind_by_name($send, ':period', $period);
 oci_bind_by_name($send, ':tren', $tren);
 oci_bind_by_name($send, ':year', $year);

 oci_bind_by_name($send, ':email', $email);
 oci_bind_by_name($send, ':pic', $pic);

 oci_execute($send,OCI_DEFAULT);

header("location:requestm.php");




?>

//////////////////////////////

我的数据库表是

CREATE TABLE  "APPLICATION" 
   (    "NAME" NVARCHAR2(100), 
    "SN" VARCHAR2(300), 
    "GENDER" VARCHAR2(100), 
    "PASS" VARCHAR2(100), 
    "UNVI" VARCHAR2(100), 
    "DEP" VARCHAR2(100), 
    "PHONE" VARCHAR2(100), 
    "TERM" VARCHAR2(100), 
    "HOUR" VARCHAR2(100), 
    "PERIOD" VARCHAR2(100), 
    "TREN" VARCHAR2(100), 
    "YEAR" VARCHAR2(100), 
    "EMAIL" VARCHAR2(100) NOT NULL ENABLE, 
    "SECTION" VARCHAR2(200), 
    "STATE" VARCHAR2(100), 
    "PIC" VARCHAR2(3000), 
    "NOTE" VARCHAR2(1000), 
     CONSTRAINT "APPLICATION_PK" PRIMARY KEY ("SN") ENABLE
   ) ;

PIC列我希望它存储图片的路径。 请帮忙

1 个答案:

答案 0 :(得分:0)

pic应该是BLOB。这是关于它的文档docs.oracle.com以及关于存储图片的示例。

顺便说一句,你的varchar2无论如何都不会工作。在php中,你的最大大小为2MB,但该列有3K字符。