首页 > 解决方案 > file_exists():open_basedir 限制生效。文件 (/tmp) 不在允许的路径内:

问题描述

我已经使用barryvdh/laravel- dompdf Laravel 包来导入 Excel 文件,但在随附的屏幕截图中出现了上述错误。

在此处输入图像描述 控制器保存一个excel文件:

    if ($request->hasFile('upload_mcq_file') and in_array($request->upload_mcq_file->extension(), array('xlsx', 'xlt', 'xltx', 'xls', 'xls', 'csv'))) {
        $image = $request->upload_mcq_file;
        $fileName = time() . '.' . $image->getClientOriginalName();
        $image->move('admin/mcqs/', $fileName);
        $path = 'admin/mcqs/' . $fileName;
    }
    $data = Excel::import(new MCQPaperImport, $path);

MCQPaperImport类如下:

class MCQPaperImport implements ToModel
{
    public function model(array $row)
    {
        return new MCQPaper([
            'product_id' => request('product_id'),
            'product_type' => request('product_type'),
            'question' => $row[0],
            'answer' => $row[1],
            'option1' => $row[2],
            'option2' => $row[3],
            'option3' => $row[4],
            'option4' => $row[5],
            'mark' => $row[6],
            'created_at' => Carbon::now('Asia/Kolkata'),
            'updated_at' => Carbon::now('Asia/Kolkata'),
        ]);
    }
}

![这张图片中提到了表模式][这张图片中提到了表模式]

标签: phplaravelframeworksts3phpframework

解决方案


推荐阅读