Thread: about blobs??

about blobs??

From
"utomo restu"
Date:
Dear all,

any body can help my problem, i am very look forward to invite my problem.
first, i was create one tabel (the table name is "pic") and i was insert 4 image
on the table. look the table like this :

latihan=# SELECT * FROM pic ;
 id |    name     | picoid |            adddate
----+-------------+--------+-------------------------------
  1 | gbr_001.png |  72591 | 2003-06-26 15:04:45.621274+07
  2 | gbr_004.png |  72593 | 2003-06-26 15:11:24.881415+07
  3 | browse.png  |  72595 | 2003-06-26 15:29:04.423781+07
  4 | bird.jpg    |  72597 | 2003-06-27 13:24:33.160357+07
(4 rows)

i was create the php skrip for display the image on browser, the php skrip from
book "Advance Web Programming PHP-Postgresql" the author is Ewald, etc:
1. upload.php
2. input_file.php
3. detail.php

for upload file to database postgres no problem, but.....
when i display the image from browser i found error like this :

The image http://server.amq.org/~andhie/book/detail.php?id=4 cannot be displayed, because it contains errors.

please help me, how i can do this.

best regards

utomo
indonesia

--
______________________________________________
http://www.linuxmail.org/
Now with e-mail forwarding for only US$5.95/yr

Powered by Outblaze

Re: about blobs??

From
"utomo restu"
Date:
thanks walid for your attantions...

i dont understand wich method i use to import the picture, but i can tell this is a php script was i create:

1. upload.php -- for upload file....
<html>
<head>
<title>Daftar File</title>
</head>
<body>
<center>
<p><h3>Daftar File Di Dalam Tabel UPLOAD</h3></p>
<font size=5>
<?php
    $konek = "host=server.amq.org dbname=latihan user=postgres password=postgres";
    $dbh = pg_connect($konek);
    if (!$dbh) {
        echo "Koneksi ke Database PostgreSQL tidak berhasil";
    exit;
    }
    $sql = "SELECT id, name, picoid, adddate FROM pic";
    $hasil = pg_exec($dbh, $sql);
    $row = pg_numrows($hasil);
    for  ($i=0; $i<$row; $i++)
    {
    $data = pg_fetch_row($hasil);
    echo $data[0].'   -   <a href="detail.php?id='.$data[0].'" target="_blank"'.">  $data[1] </a><br>";
    }
 ?>

<br><hr>
<h3>Upload File</h3>
<form id="data" method="post" action="input_file.php"
      enctype="multipart/form-data">
<p><font size=3><b>Pilih File yang ingin di Upload</b></font></p>
<input name="testfile" type="file" size="50" maxlength="100000"><br><br>
<input name="submit" type="submit" value="KIRIM">
</form> </font> </center> </body> </html>


2. input_file.php

<?php
    $konek = "host=server.amq.org dbname=latihan user=postgres password=postgres";
    $dbh = pg_connect($konek);
    if (!$dbh) {
        echo "Koneksi ke Database PostgreSQL tidak berhasil";
    }
// check file upload

    if ($testfile)
    {
       if (is_uploaded_file ($testfile))
        {
           chmod ($testfile, 0777);

        //query for upload file in to database
        $sql = "INSERT INTO pic (name, picoid) VALUES";
        $sql .= "('$testfile_name', lo_import('$testfile'))";

        $hasil = pg_exec($dbh, $sql);
        if (!$hasil)
        {
          echo "File yang dimaksud tidak berhasil di UPLOAD<br><br><br>";
          exit;
    }
        else
        {
          echo "<h1>File <b>$testfile_name</b> BERHASIL di UPLOAD</h1><br> ";
        }
      }
      else
      {
         echo "Tidak ada File yang telah di UPLOAD";
      }
   }
        pg_close($dbh);
?>


3. detail.php  -- for display the image.

<?php
    $konek = "host=server.amq.org dbname=latihan user=postgres password=postgres";
    $dbh = pg_connect($konek);
    if (!$dbh) {
        echo "Koneksi ke Database PostgreSQL tidak berhasil";
    exit;
    }
    $sql = "SELECT id, name, picoid, adddate FROM pic WHERE id=$id";
    $hasil = pg_exec($dbh, $sql);
    $data = pg_fetch_row($hasil, 0);
    if    (!$data)
    {
    echo "Tidak ditemukan file yang dimaksud";
    }
    else
    {
    Header ("Content-type: image/png");
    pg_exec($dbh, "BEGIN");
    $ofp = pg_loopen($data[2], "r");
    if  (!$ofp)
    {
        echo "File Tersebut Tidak Dapat Diakses";
    }
    $img = pg_loreadall($ofp);
    print $img;
    pg_loclose($ofp);
    pg_exec($dbh, "END");
    }
  ?>

where syntax from the php script on top, make the problem ???
i hope all of you unnderstand my questions....

utomo
indonesia

> hello
> sorry for my english, which method tou use to import the picture?
> Walid
> Le Vendredi 27 Juin 2003 11:29, vous avez écrit :
> > Dear all,
> >
> > any body can help my problem, i am very look forward to invite my problem.
> > first, i was create one tabel (the table name is "pic") and i was insert 4
> > image on the table. look the table like this :
> >
> > latihan=# SELECT * FROM pic ;
> >  id |    name     | picoid |            adddate
> > ----+-------------+--------+-------------------------------
> >   1 | gbr_001.png |  72591 | 2003-06-26 15:04:45.621274+07
> >   2 | gbr_004.png |  72593 | 2003-06-26 15:11:24.881415+07
> >   3 | browse.png  |  72595 | 2003-06-26 15:29:04.423781+07
> >   4 | bird.jpg    |  72597 | 2003-06-27 13:24:33.160357+07
> > (4 rows)
> >
> > i was create the php skrip for display the image on browser, the php skrip
> > from book "Advance Web Programming PHP-Postgresql" the author is Ewald,
> > etc: 1. upload.php
> > 2. input_file.php
> > 3. detail.php
> >
> > for upload file to database postgres no problem, but.....
> > when i display the image from browser i found error like this :
> >
> > The image http://server.amq.org/~andhie/book/detail.php?id=4 cannot be
> > displayed, because it contains errors.
> >
> > please help me, how i can do this.
> >
> > best regards
> >
> > utomo
> > indonesia

--
______________________________________________
http://www.linuxmail.org/
Now with e-mail forwarding for only US$5.95/yr

Powered by Outblaze