首页 > 解决方案 > finfo_file(C:\xampp\tmp\phpC546.tmp):打开流失败:没有这样的文件或目录

问题描述

Yii2:我正在更新 pdf 文件,但是在执行操作时出现此错误。源代码中的路径被创建,就像文件被保存在创建的路径和数据库中一样。但在执行此过程后,我收到此错误

Script PHP-Yii2

// Update PDF


 $pathPdf = 'uploads/pdf/userSettings/';
        if (!is_dir($pathPdf)) {
            mkdir($pathPdf, 0777, true);
        }
        if(UploadedFile::getInstance($model, 'file_pdf')){
            $model->file_pdf = UploadedFile::getInstance($model, 'file_pdf');
            $file = $pathPdf . md5($model->company_name) . '.' . $model->file_pdf->extension;
            $model->pdf_front_path = $file;
        }
        if (!$model->validate()) {
            $errors = $model->errors;
            $this->showErrorMessages($tab);
        } else {
            if ($model->save()) {
                if (UploadedFile::getInstance($model, 'file_pdf')) {
                    $model->file_pdf->saveAs($file);
                }
            } else {
                Yii::$app->session->setFlash('error', Yii::t('app', 'error_save'));
            }
        }

你能帮我吗,我已经尝试了几件事,但没有任何对我有用

标签: phppdfyii2

解决方案


 You can solve it simply by moving the line ''$model->file_pdf->saveAs($file);'' under '''$model->pdf_front_path = $file;''' for some strange reason Yii jumps that error with the routes, it is as if it did a double validation of this route, but on the second occasion it validates it no longer finds it.

    the code stayed like this

    // Update PDF


     $pathPdf = 'uploads/pdf/userSettings/';
            if (!is_dir($pathPdf)) {
                mkdir($pathPdf, 0777, true);
            }
            if(UploadedFile::getInstance($model, 'file_pdf')){
                $model->file_pdf = UploadedFile::getInstance($model, 'file_pdf');
                $file = $pathPdf . md5($model->company_name) . '.' . $model->file_pdf->extension;
                $model->pdf_front_path = $file;
    $model->file_pdf->saveAs($file);
            }

after that you can already perform the validations you want, but they are not from the route

推荐阅读