可能重复:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
在codeigniter中,我无法从文件夹下载pdf文件。在尝试下载时 在我们的服务器中它正在工作但是,在客户端的服务器中不起作用。可能是什么原因?
这是我在控制器中的代码。
$directory = './pdf/';
set_realpath($directory);
$file = $directory.'dwn.pdf';
$fp = fopen($file,'wb');
$pdfcode = "---some texts----";
fwrite($fp,$pdfcode);
fclose($fp);
$data = file_get_contents(base_url()."pdf/dwn.pdf"); // Read the file's contents
$name = 'dwn.pdf';
force_download($name, $data);
这是错误。
A PHP Error was encountered
Severity: Warning
Message: fopen(./pdf/dwn.pdf) [function.fopen]: failed to open stream: Permission denied
Filename: controllers/pms.php
Line Number: 732
A PHP Error was encountered
Severity: Warning
Message: fwrite() expects parameter 1 to be resource, boolean given
Filename: controllers/pms.php
Line Number: 733
A PHP Error was encountered
Severity: Warning
Message: fclose() expects parameter 1 to be resource, boolean given
Filename: controllers/pms.php
Line Number: 734
答案 0 :(得分:0)
可能是文件名和/或权限,请尝试此修改后的代码
$directory = './pdf/';
set_realpath($directory);
$file = $directory.'dwn.pdf';
chmod($file,0777);
$fp = fopen($file,'wb');
$pdfcode = "---some texts----";
fwrite($fp,$pdfcode);
fclose($fp);
$data = file_get_contents($file); // Read the file's contents
$name = 'dwn.pdf';
force_download($name, $data);