I have a blob which we receive from a Firebird 3.0 database.
if($dbh = ibase_connect($db,$username,$password, 'UTF-8')){
echo "Connecton steht zur Firebird DB steht! <br>";
$sql = "SELECT MEMO FROM DMS where ID = '44'";
// Execute query
$rc = ibase_query($dbh, $sql);
// Get the result row by row as object
$data = ibase_fetch_object($rc);
$blob_data = ibase_blob_info($data->MEMO);
$blob_hndl = ibase_blob_open($data->MEMO);
$inhalt = ibase_blob_get($blob_hndl, $blob_data[0]);
With
ibase_blob_echo($data->MEMO)
there comes a lot of signs in browser, so the SQL query works. Now I'd like to write the content (its a PDF) in a pdf file on disk.
Every try didn't succeed:
file_put_contents('test.pdf', $inhalt);
file_put_contents('test.pdf', ibase_blob_echo($data->MEMO));
and much more.
When we try to open the PDF File with Acrobat Reader, there comes an error message: no PDF File / File-type is not supported
How can we fix this?
thank you for your answers ... We interpreted them in a way, that the code above is basicly correct. After a while, we found out, that the error apears because we changed the charset in the DB Connect to UTF8 for the varchar Fields. For the blob we connect now without Charset change and the readout work properly. Thank you again.
$dbh = ibase_connect($db,$username,$password)
Related
please tell me how can i insert pdf or doc files into oracle blob field .
this is the code which i use for varchr data type and this is fine but how can i save the files into blob data type please help me !!!
if(isset($_POST['elm1'])) {
$pdata=$_POST['elm1'];
$profile_name=$_POST['profilename'];
$profile_id=$_POST['profileid'];
$query = "insert into prepaid_profiles values('$profile_id' , '$profile_name','$pdata')";
$result = oci_parse($dbc,$query);
oci_execute($result);
oci_close($dbc);
When user uploads file, save it in server, show only link to it. When saved text from editor, you save only link (with rest of text). File is still on server.
But if you really need to make your database huge and slowly, read uploaded file with file_get_contents, that convert it to base64 and save to database long string (no idea why it's better).
TinyMCE don't need file content in <textarea>.
We have asoftware engineering project i need to put picture in the database using blob of php interbase using firebird server. Could someone give me some reerences to do it. Or some example?
Regards.
First create a method call insertBlob or name it anything you want.
then open the file as binary, 'rb' means read binary so you can save it to your database as a blob type.
public function insertBlob($filePath,$mime){
$blob = fopen($filePath,'rb');
$sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)";
$stmt = $this->conn->prepare($sql);
$stmt->bindParam(':mime',$mime);
$stmt->bindParam(':data',$blob,PDO::PARAM_LOB);
return $stmt->execute();
}
now you can do somethiling like this..
insertBlob('C:/picture1.png','image/png');
I have a postgres database with stored images 'bytea' type and I try to display them into a browser with PHP. I found the way to display one of them but I can't make it for more than one. The code I use is the following:
File Name - display_image.php
$conn = pg_connect("dbname=test user=postgres password=postgres");
$temp = '/home/postgres/tmp.jpg';
$query = "select lo_export(image, '$temp') from map ";
$result = pg_query($query);
if($result)
{
while ($line = pg_fetch_array($result))
{
$ctobj = $line["image"];
echo "<IMG SRC=show.php> </br>";
}
}
else { echo "File does not exists."; }
pg_close($conn);
File Name - show.php
header("Content-type: image/jpeg");
$jpeg = fopen("/home/postgres/tmp.jpg","r");
$image = fread($jpeg,filesize("/home/postgres/tmp.jpg"));
echo $image;
The problem seems to be the "tmp.jpg" virtual file which displays only one image. If the result of the query is 7 images then it displays 7 times the same image within a while loop. How can I solve this?
Thanks for the interest!
I did this some time ago for bytea.
You need to run your bytea data through pg_unescape_bytea. See http://php.net/manual/en/function.pg-unescape-bytea.php
Basically your SQL query returns the bytea field in an escaped format.
However this is not what you are doing. And so the above is just for the next poor sap who comes here looking for bytea help. Please amend to note you are using LOB's not BYTEA's.
Also note that your code there is not concurrency safe. If two users request different images, my guess is that you will get both users getting different images. For this reason you should add the oid to the retrieval url, and name your file /tmp/$oid.jpg where $oid is the oid of the large object. You will need to retrieve that info (I believe it looks like it is stored in the image field of map?). On the other hand that assumes that all files are essentially public. if that's not the case, you want to move everything into the show_image.php and clean up when you are done.
I know it's not the greatest technique, but coming from Foxpro and Dbase background, some habits just don't die. I am absolutely fresh in PHP and trying to re-create learning curve of my earlier programming experience.
I have drilled GOOGLE for the issue and tried to come up with the script, only issue is sometimes I came up with garbles, sometime empty screen, sometimes only IMAGE.
The scenario is If I am able to create this simple script, I will probably understand how to handle images issue.
I have a database in my MYSQL called crm. In the database I have a table called mast_cust with fields f_name, l_name and pic (BLOB)
I already have some records in them.
What I understood was:
Images and Data (Textual) cannot be printed together
You have to have two scripts , one gathering the image and the other gathering data
The one which gathers data , calls the one which collects images and prints it.
What I want is, to see data in tabular format
First Name | Last Name | Image
These are my two scripts, which is the one which prints garble
Script 1 : Main PHP file - list.php
Script 2 : Image Storing Script: pix.php
list.php
<?php
$errmsg = "";
if (! #mysql_connect("localhost","root","Admin"))
{
$errmsg = "Cannot connect to database";
}
#mysql_select_db("crm");
$strSQL = "select f_name,l_name,pic from mast_cust";
$rsPix = mysql_query($strSQL);
$numRows = mysql_numrows($rsPix);
$i = 0;
while($i < $numRows){
?>
<img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pic"); ?>"/>
<?php
$i++;
}
?>
Script 2 pix.php
<?php
$errmsg = "";
if (! #mysql_connect("localhost","root","Admin"))
{
$errmsg = "Cannot connect to database";
}
#mysql_select_db("crm");
if (IsSet($_GET['pixID'])){
$gotten = #mysql_query("select pic from pix where cust_id = ".$_GET['pixID']);
header("Content-type: image/jpeg");
while ($row = mysql_fetch_array($gotten))
{
print $row['pic'];
}
mysql_free_result($gotten);
}
?>
Any help resolving this issue is highly appreciated.
Thanks and Regards
It seems like you're storing the jpeg image as a blob in mysql.
1.) You can only send one pic at a time. So no need for a for loop.
2.) If so, you'll need to format the output of the data for the pic, so that a browser can read it.
I would recommend against this approach. You should avoid using a relational database for storing images. Try storing the jpegs on a regular filesystem or a file server (like S3), and store the url to it in the database.
If obfuscating the image url isn't enough, try the following approach:
Echo/print a jpg-image with php, for safety?
It uses:
http://php.net/manual/en/function.readfile.php
Im trying the following code:
<?php
$workbook = "D:\b2\\test.XLS";
$sheet = "Sheet1";
#Instantiate the spreadsheet component.
$ex = new COM("Excel.sheet") or Die ("Did not connect");
#Get the application name and version
print "Application name:{$ex->Application->value}<BR>" ;
print "Loaded version: {$ex->Application->version}<BR>";
#Open the workbook that we want to use.
$wkb = $ex->application->Workbooks->Open($workbook) or Die ("Did not open");
#Create a copy of the workbook, so the original workbook will be preserved.
$ex->Application->ActiveWorkbook->SaveAs("D:\b2\Ourtest.xml");
#$ex->Application->Visible = 1; #Uncomment to make Excel visible.
#Optionally, save the modified workbook
$ex->Application->ActiveWorkbook->SaveAs("D:\Ourtest.xml");
#Close all workbooks without questioning
$ex->application->ActiveWorkbook->Close("False");
unset ($ex);
?>
This actually works and creates the Ourtest.xml file. But im getting characters like:
ÐÏࡱá > þÿ þÿÿÿ
I have tried with SaveAs("D:\Ourtest.pdf") and it says the file has been corrupted or incorrectly decoded.
Can anyone help me please?Thanks
That is because you are saving it as Excel Format. Check the Excel documentation for how to save it as an XML document - it might be a separate paramter to SaveAs or a different method alltogether (Export*).
EDIT: It seems SaveAs is the right method to use. Check the msdn documentation here. You probably want to specify the second parameter FileFormat. Maybe setting it to the XlFileFormat.xlXMLSpreadsheet value?
Problem solved by using
$ex->Application->ActiveWorkbook->SaveAs("D:\Ourtest.xml",46);
46 is the value for xlXMLSpreadsheet
Thanks everyone