【问题标题】:FileNotFoundException in Filesystem.php line 41: File does not exist at path (LARAVEL)Filesystem.php 第 41 行中的 FileNotFoundException:路径中不存在文件 (LARAVEL)
【发布时间】:2016-09-20 14:07:53
【问题描述】:

我正在尝试将上传的文件读取到我的系统,但我无法读取它,因为每次我这样做时都会收到此错误FileNotFoundException in Filesystem.php line 41: File does not exist at path /var/www/html/.. 我不知道我在其中做错了什么。我正在使用File::get() 方法。下面是代码。感谢您的帮助

public function getUploadedFile() {

    $destinationPath = 'uploads';
    $path= public_path()."/". $destinationPath;

    echo $path; // this was to check whether am I getting the right path or not which I am getting.

    $upload = new Upload; 
    $content = utf8_encode(File::get($path ."/". $upload->file_name));
    return $content;
}

【问题讨论】:

  • 是您的文件权限是 644,文件夹权限是 077。检查一次并且提供文件的完整路径并检查
  • 你为什么要这样做? $upload = new Upload; $content = utf8_encode(File::get($path ."/". $upload->file_name)); return $content; 为什么不直接将 $path 返回到视图并显示它!
  • 如何处理word文件?我的意思是每个单词文件都会有不同的文本、字体等?
  • 我的意思是显示单词或pdf文件的视图应该是什么?我有一个可以下载 excel 文件但不知道如何一起使用所有这些文件?
  • 我也试过这段代码,但这只是给了我一个空白页,没有别的$file_name = File::get($file_name); $response = Response::make($file_name, 200); $response->header('Content-Type', 'application/vnd.ms-excel); return $response; }

标签: php laravel file-upload laravel-5.2 filereader


【解决方案1】:

型号

public function setFileAttribute($file){
$this->attributes['file'] = Carbon::now()->second.$file->getClientOriginalName();
$name = Carbon::now()->second.$file->getClientOriginalName(); 
\Storage::disk('local')->put($name, \File::get($file));
    }

fileSystems.php

   'disks' => [

    'local' => [
        'driver' => 'local',
       // 'root' => storage_path('public'),
        'root' => public_path('storage'),
    ],

    'public' => [
        'driver' => 'local',
        'root' => storage_path('storage'),
        'visibility' => 'public',
    ],

    's3' => [
        'driver' => 's3',
        'key' => 'your-key',
        'secret' => 'your-secret',
        'region' => 'your-region',
        'bucket' => 'your-bucket',
    ],

],

【讨论】:

  • 请在您的代码 sn-p 中添加一些 cmets 和描述。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多