无法从文件夹下载文件
在 codeigniter 中 select 中给出的布尔值,我无法从文件夹下载 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
Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
In codeigniter I can't download a pdf file from a folder. When trying to download it,
in our server it is working but, in client's server is not working. What can be the reason?
This is my code in controller.
$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);
This is the error.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是文件名和/或权限,尝试这个修改后的代码
Could it be the file name and/or permisisons, try this modified code