2013-05-21 151 views
0

我想生成和發送創建的PDF到一個文件夾,但我得到一個錯誤,這個錯誤:保存生成的PDF直接到文件夾中的文件夾 - 笨

A PHP Error was encountered 

Severity: Warning 

Message: file_put_contents(http://localhost/NQCL1/workbooks/NDQA000000001/NDQA000000001.pdf) [function.file-put-contents]: failed to open stream: HTTP wrapper does not support writeable connections 

Filename: libraries/Dompdf_lib.php 

Line Number: 13 

Dompdf_lib.php //庫文件

class Dompdf_lib extends Dompdf{ 

     function createPDF($html, $filename='', $stream=TRUE){ 
      $this->load_html($html); 
      $this->render(); 
      $this->set_paper('a4', 'potratit'); 
      if ($stream) { 
       //$this->stream($filename.".pdf"); - This works just ok 
       file_put_contents(base_url().'workbooks/s'.$filename.'/'.$filename.".pdf", $this->output()); 

      } else { 
       return $this->output(); 
      } 
     } 

} 

coa.php //控制器

function generateCoaDraft($labref,$offset=0) { 
    // error_reporting(1); 
    $data['labref'] = $labref = $this->uri->segment(3); 
    $data['information'] = $this->getRequestInformation($labref); 
    $data['tests_requested'] = $this->getRequestedTests($labref); 
    $data['trd'] = $this->getRequestedTestsDisplay2($labref); 
    $data['compedia_specification'] = $this->getCOABody($labref); 
    $html = $this->load->view('coa_v', $data, true); 
    $this->dompdf_lib->createPDF($html, $labref); 
} 

這行工作正常,如果我用它來代替file_put的......,如果是AY STREAM = FALSE,它返回空白頁

$this->stream($filename.".pdf"); 
+0

只需從命令寫入文件之前刪除$ this->即可。 file_put_contents()是一個本地PHP函數。 – Rooneyl

+0

我已刪除$ this,現在出現新的連接錯誤 – alphy

+1

該錯誤是由於在文件路徑中使用了http,因此您在路徑中使用了base_url()。結帳http://stackoverflow.com/questions/7490164/http-wrapper-does-not-support-writeable-connections-codeigniter-problem – Rooneyl

回答

2

file_put_contents是土生土長的PHP函數,所以改線;

file_put_contents('workbooks/s'.$filename.'/'.$filename.".pdf", $this->output()); 

通過預先考慮$ this->系統試圖找到屬於類的函數(它不存在),因此錯誤。

+0

感謝它的工作正常 –

0

我已經意識到,我試圖與服務器通過HTTP進行通信的,我修改了代碼,只需直接路徑和它的工作,感謝guyz

這樣的:

file_put_contents(base_url().'workbooks/s'.$filename.'/'.$filename.".pdf", $this->output()); 

這樣:

file_put_contents('workbooks/s'.$filename.'/'.$filename.".pdf", $this->output()); 
相關問題