2014-12-03 33 views
0

我使用DB2,PHP和Yii Framework管理CLOB和BLOB類型(儘管我只使用php)。我正在上傳文件到DB2。使用CLOB和BLOB類型。但我有一個問題,我沒有下載文件。我獲得了一個資源,流類型與此代碼:如何獲取和管理數據庫的流資源? PHP-DB2

if(is_resource($model->file_content)) echo 'resource of type:'; 
echo '<br>'; 
echo get_resource_type($model->file_content); 

我需要將此流轉換爲文件下載到網絡中。

我已經試過:print_r(stream_get_contents($model->file_content));

,並使用fread()

有沒有PHP函數來獲取流類型?

編輯:類型是 「IBM PDO高球流」,它獲得與stream_get_meta_data($model->file_content);

而且,我已經試過:

header('Pragma: public'); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Content-Transfer-Encoding: binary'); 
header('Content-length: '.$model->file_size); 
header('Content-Type: '.$model->file_type); 
header('Content-Disposition: attachment; filename='.$model->file_name); 

echo $model->file_content; 

但結果是用HTML文件我頁。

你能幫我嗎?謝謝

回答

0

有沒有必要編寫純PHP代碼。 Yii有一個叫做sendFile的方法來處理這個問題。請看:

Yii::app()->request->sendFile('file.ext', "Content Of File", "Mime Time",TRUE); 

官方文檔定義sendFile()

將文件發送給用戶。

public void sendFile(string $fileName, string $content, string $mimeType=NULL, boolean $terminate=true) 

還建議使用的Yii的CFileHelper課呢。

+0

我不想發送文件。我需要在DB2的CLOB列中插入並獲取文件。 – vicenrele 2014-12-04 13:20:36

+0

@vicenrele其實'sendFile'的用例是下載一個文件。或者可能是這是我的誤解?您是否在談論下載DB2的Clob文件或存儲交互clob? – 2014-12-04 14:09:43

相關問題