Solved

store image ina database via html form

Posted on 2004-09-05
6
275 Views
Last Modified: 2013-12-12
Im going to store image in a oracle database. The image is required to upload via a HTML form. I create a table with three collum which are ID (number), name(varchar2) and body (blob). when im submit my imahe via form it gives three errors as follows.

1.Warning: ociparse(): OCIParse: ORA-00972: identifier is too long in /usr/local/apache/htdocs/image_store.php on line 19

2.Warning: ociexecute(): supplied argument is not a valid OCI8-Statement resource in /usr/local/apache/htdocs/image_store.php on line 30

3.Warning: Cannot modify header information - headers already sent by (output started at /usr/local/apache/htdocs/image_store.php:19) in /usr/local/apache/htdocs/image_store.php on line 40

Already Im strugling 1 1/2 day with these errors and 2 weeks to develop that image upload part. But still i couldnt make it sucsess. please help!!!! following is my script

<?php

$c=OCILogon("scott", "tiger");
  if ( ! $c ) {
    echo "Unable to connect: " . var_dump( OCIError() );
    die();
  }
$name = $_REQUEST["name"];
$image = $_REQUEST["image"];
$ffile = fopen($_FILES['image']['tmp_name'], "rb");
$content = fread($ffile,$_FILES['image']['size']);
$eimage = addslashes($content);

// data to insert into the project table

$qu = "insert into test_images (ID, NAME, BODY) values ('2','$name','$eimage')";
$sql = OCIParse($c,$qu);

// verify that SQL is valid
      $arrError = OCIError($sql);
      if ($arrError['code'])
      {
        print $arrError['message'];
        OCIRollback($c);
        exit;
      }
// execute the query
OCIExecute($sql,OCI_DEFAULT);
// make sure there were no errors with our query
      $arrError = OCIError($sql);
      if ($arrError['code'])
      {
        print $arrError['message'];
        OCIRollback($c);
        exit;
      }
      OCICommit($c);
header("Location: thank_you.htm");
?>



0
Comment
Question by:hkdarshana
  • 3
6 Comments
 
LVL 32

Expert Comment

by:ldbkutty
ID: 11988993
I dont have a direct answer for you. The comments in PHP Manual should be of help to you.

>> 1.Warning: ociparse(): OCIParse: ORA-00972: identifier is too long in /usr/local/apache/htdocs/image_store.php on line 19
http://uk.php.net/ociparse

>> 2.Warning: ociexecute(): supplied argument is not a valid OCI8-Statement resource in /usr/local/apache/htdocs/image_store.php on line 30
http://uk.php.net/manual/en/function.ociexecute.php

>> 3.Warning: Cannot modify header information - headers already sent by (output started at /usr/local/apache/htdocs/image_store.php:19) in /usr/local/apache/htdocs/image_store.php on line 40

This error is clear. You *cannot* have header() function after any information sent to the browser. (i.e.  * NO echo or print statements or HTML tags* should be present before the header() function. )

You should have even a single white space before the <?php.

Example:
----------

1. No whitespace before the "<?php" (remove double-quotes) tag. I mean

<?php  --->RIGHT.

whereas

 <?php  -->WRONG. (see the white space before <?php )

2. There should not be any HTML tags or echo statements before the header. But, You can have in the die() statement, because die() terminates the application.
0
 
LVL 32

Expert Comment

by:ldbkutty
ID: 11988997
>> You should have even a single white space before the <?php.

Actually, i mean:

You should *not* have even a single white space before the <?php.
0
 

Author Comment

by:hkdarshana
ID: 11995045
nyway if fixed above errors. Now i can store image in a oracle table via  "insertimage.php"  page. When Im query the db it shows ID and NAme fields. I cant query for BLOB data in sqlplus. So that there is no such a way to validate the image upload.

My table is

Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                                                 VARCHAR2(5)
 NAME                                               VARCHAR2(30)
 BODY                                               BLOB
 
Im try to view image using view.htm and getimage.php files. There are no any error massages. But it doesnt show anything. my pages as follows.

insertimage.php
.....................................................................................................................................
<?php
session_start();
if($_POST['submit']){

$c=OCILogon("scott", "tiger");
  if ( ! $c ) {
    echo "Unable to connect: " . var_dump( OCIError() );
    die();
  }
$image = '$_POST["image"]';
$ffile = fopen($_FILES['image']['tmp_name'], "rb");
$content = fread($ffile,$_FILES['image']['size']);
$eimage = addslashes($content);


// data to insert into the project table
$qu = "insert into test_images (ID, NAME, BODY) values('3','".$_POST['name']."','$eimages')";
$sql = OCIParse($c,$qu);
// verify that SQL is valid
      $arrError = OCIError($sql);
      if ($arrError['code'])
      {
        print $arrError['message'];
        OCIRollback($c);
        exit;
      }
// execute the query
OCIExecute($sql,OCI_DEFAULT);
// make sure there were no errors with our query
      $arrError = OCIError($sql);
      if ($arrError['code'])
      {
        print $arrError['message'];
        OCIRollback($c);
        exit;
      }
      OCICommit($c);
header("Location: thank_you.php");
} else{
?>

<html>
<head><title>Store binary data into SQL Database</title></head>
<body>


    <form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
    File Description:<br>
    <input type="text" name="name"  size="40">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
    <br>File to upload/store in database:<br>
    <input type="file" name="image"  size="40">
    <p><input type="submit" name="submit" value="submit">
    </form>

<?php

}

?>

</body>
</html>

view.htm
.......................................................................................................................................
<html>
<head><title>Image</title></head>
<body>
<img src ="getimage.php?NAME=dinushi">
</body>
</html>

getimage.php
....................................................................................................................................
<?php
      header("Content-type: image/gif");

         // now select back our data
         $c=OCILogon("scott", "tiger");
         $qu ="select body from test_images";
         $sql = OCIParse($c, $qu);
         @OCIExecute($sql, OCI_DEFAULT);
         // check our query
         $arrError = OCIError($sql);
         if ($arrError['code'])
       {
           print $arrError['message'];
           exit;
         }

      //      $nrows = ocirowcount($sql);

      //      if($nrows == 1)
//      {


            OCIFetchInto($sql, $row, OCI_B_BLOB);
      
            echo $row['BODY'];
            
//      }
.................................................................................................................................................................

Please help me to fix this. Im already spend more than 2 weeks for this bit. Any help I really appreciate.

0
 
LVL 32

Accepted Solution

by:
ldbkutty earned 500 total points
ID: 12001498
I am sorry, i dont have any experience in using sqlplus with PHP. But, storing image directly and retrieveing it is unnecessary and it will make your script harder.

My suggestion is upload the image in some folder and store the location of the image file in the database. So, if you want to display the image, you just need to retrieve the file path from the database.

I hope you understand. If not, let me know and i will try my best.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to use Initialization Vector for openssl_encrypt() 5 58
Redirect 301 from one address  to another 5 25
IP 10.0.1.2 / 255.0.0.0 61 56
Ajax and PHP 4 29
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question