php - 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'));
}
}
你能帮我吗,我已经尝试了几件事,但没有任何对我有用
解决方案
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
推荐阅读
- google-apps-script - 无法在谷歌应用脚本中使用 DocumentApp.openById() 打开文档
- c# - 查找两个锚点之间的元素包括具有 XPath 的锚点的父级
- macos - 如何以编程方式在 macOS SwiftUI 应用程序中打开设置窗口
- spring-boot - Spring Cloud 配置服务器未读取本地 git 存储库中的属性文件
- node.js - NodeJs Express 响应处理程序
- java - org.hibernate.HibernateException:未知实体:null - 不识别子标准中的标准别名
- angular - Angular Reactive Form,valueChanges 运行到“最大调用堆栈大小”
- javascript - 安装 Angular 的问题
- ios - CoreData+CloudKit | 开/关 iCloud 同步切换
- floating-point - ULP 中的浮点错误(最后一位的单位)