无法从文件夹下载文件

发布于 2024-12-18 20:22:59 字数 1262 浏览 2 评论 0原文

可能的重复:
mysql_fetch_array() 需要参数 1是资源,在 select 中给出的布尔值

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倒带 2024-12-25 20:22:59

可能是文件名和/或权限,尝试这个修改后的代码

$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); 

Could it be the file name and/or permisisons, try this modified code

$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); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文