【问题标题】:PDF File Reading using Laravel PHP Error : readfile($path): failed to open stream: No such file or directory使用 Laravel PHP 读取 PDF 文件错误:readfile($path): failed to open stream: No such file or directory
【发布时间】:2020-03-18 01:38:31
【问题描述】:
public function open()
{
    $path = '2020/March/tes.pdf';
    if (Storage::exists($path)) {
        Storage::get($path);
        // dd(Storage::files('2020\March'));
        echo readfile($path);
        //echo ini_get("open_basedir");
    } else {
        Echo ('File didnt exist');
        }
}

我是网络编程新手,这里我打算在 app/public/2020/March 中打开一个 .pdf 文件,文件和路径存在,但我无法打开文件,上面写着“readfile(2020/March /tes.pdf):无法打开流:没有这样的文件或目录”。 我尝试了互联网上的教程,链接存储,存储在应用程序/公共中,缓存配置,清除配置,将默认文件系统更改为公共。 谢谢。

【问题讨论】:

  • 尝试使用绝对路径?

标签: php laravel file


【解决方案1】:

您收到此错误是因为您的路径不正确。要访问公用文件夹中的文件,请使用 public_path() 函数

根据 Laravel 文档:

public_path 函数将完全限定路径返回到 公共目录。您也可以使用public_path 函数 生成公共中给定文件的完全限定路径 目录

改变

 $path = '2020/March/tes.pdf';

$path = public_path("2020/March/tes.pdf");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-21
    • 2016-08-14
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    • 2020-02-09
    • 2021-10-29
    • 2018-09-09
    相关资源
    最近更新 更多