binary data into postgresql in bytea

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



HI!


I wrote the code how to upload and insert binary data into postgresql.

 <?php

 $original_tmp = $_FILES['UploadedFile']['tmp_name'];
 $original_name = $_FILES['UploadedFile']['name'];
 $original_size = $_FILES['UploadedFile']['size'];
 $original_type = $_FILES['UploadedFile']['type'];
 print("<hr>\n");

 $fileHandle = fopen($original_tmp, "r");
 $binaryContent = fread($fileHandle, $original_size);
 $binaryContent = pg_escape_bytea($binaryContent);
 fclose($fileHandle);

 $sql_insert = "INSERT INTO objects(b_col, file_name, file_size,
file_type, file_date) VALUES
('$binaryContent'::bytea,'$original_name','$original_size','$original_type',now())";
 pg_query($sql_insert) or DIE ("Could not perform INSERT to table:
".pg_lst_error());
 ?>




Does anyone know right code?
I do not think this is write code for postgresql.

The field which binary data is stored is "bytea."


Regards,
hiro

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux