Yii Framework Forum: Read Pdf From Database (Psql Large Object) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Read Pdf From Database (Psql Large Object) Rate Topic: -----

#1 User is offline   ape 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 04-March 13

Posted 04 March 2013 - 09:46 AM

Hello everybody!

I'm using a postgresql 9.1 database, where a pdf file is stored in a large object field (oid). Now I want to show the pdf-file in a link where the user can click for watching it. I've searched a long time for doing this with Yii but without success.
I wondered if Yii bringing such stuff with it?
Or do I have to use the php pg_lo_open and pg_lo_read function itself? If so how can I get the database connection ressource needed by this functions (which normally will be returned from pg_connect function)? I thought about
Yii::app()->db->getPdoInstance()
but this seems not the correct ressource.

Can anyone help me please?

Regards
0

#2 User is offline   ape 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 04-March 13

Posted 05 March 2013 - 02:25 AM

Any ideas?
0

#3 User is offline   ape 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 04-March 13

Posted 05 March 2013 - 05:28 AM

I found this tutorial and followed it.
In my model I added the following rule:
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('document', 'file', 'types' =>'pdf'),
	        );
	}

In my controller I added the following action:
	public function actionShowDoc($id) {
		$model = Docs::model()->findByPk($id);
		$this->renderPartial('_pdf_test', array('model'=>$doc));
        }

And I added a new view file _pdf_test.php where I put:
<?php
header('Conent-Type: PDF');
print $model->document;
?>


But it displays only the large object id (for example 18631) which you can also see in database by sql statement.

Am I doing something wrong?

Regards
0

#4 User is offline   ape 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 04-March 13

Posted 06 March 2013 - 02:52 AM

Hello again,

yesterday I tried to use a bytea instead of a large object type in my database and doing the stuff which I wrote above. This works fine if I put the result of
$model->document
in the
stream_get_contents
function, reading here.

I can't use this function for the large object type because in this case
$model->document
returns not a resource. At this time I use following workaround:
Yii::app()->db->createCommand("select lo_export(docs.document, '/tmp/$model->name.pdf') FROM docs where document=$model->document")->execute();

This statement saves the large object as pdf into /tmp folder. Then I load and display it in pdf viewer.

Has anyone another idea?

Regards
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users