Php 找不到Yii finfo_文件()
我正在用Yii上传一些文件。我得到了以下错误Php 找不到Yii finfo_文件(),php,yii,Php,Yii,我正在用Yii上传一些文件。我得到了以下错误 finfo_file() [<a href='function.finfo-file'>function.finfo-file</a>]: File or path not found 'C:\xampp\tmp\phpF48A.tmp' 任何帮助,非常感谢。要添加,文件保存在正确的目录中,但它的记录不保存在数据库中 谢谢 琼尼 更新代码 模型 控制器(几乎是默认的Gii代码) 我发现Yii的文件验证系统的mimeType检
finfo_file() [<a href='function.finfo-file'>function.finfo-file</a>]: File or path not found 'C:\xampp\tmp\phpF48A.tmp'
任何帮助,非常感谢。要添加,文件保存在正确的目录中,但它的记录不保存在数据库中
谢谢
琼尼
更新代码
模型
控制器(几乎是默认的Gii代码)
我发现Yii的文件验证系统的mimeType检查部分有点问题(或者至少是喜怒无常;-)。您可能会遇到许多小故障,但这与我以前看到的错误不同 根据@PeterM的评论,看起来确实找不到您的临时文件,这意味着很难完成验证。如果禁用mimeType验证,然后在上载文件时重命名该文件(以便您知道它应该在哪里),您的文件最终会被上载吗
最好确保您的上传系统非常可靠,然后添加mimeType验证。因为他们可能会有点挑剔…我真的不知道为什么会这样,也不知道这有什么问题。我所能展示的就是最终的代码,它似乎工作得很好(除了我还没有对.docx上传进行排序。不过所有其他类型的上传都很好) 型号:
array('file', 'file', 'on' => 'insert', 'maxSize'=> 512000, 'maxFiles'=> 1,
'mimeTypes' => 'application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/rtf, text/plain',
'tooLarge'=> 'File cannot be larger than 500KB.',
'wrongType'=> 'Format must be:<code>.doc</code>, <code>.docx</code>, <code>.txt</code>, <code>.rtf</code>'),
public function actionCreate() {
$model = new File;
if (isset($_POST['File'])) {
$model->setAttributes($_POST['File']);
// Set file
$model->file = CUploadedFile::getInstance($model,'file');
// Set directory
$dest = Yii::getPathOfAlias('application.uploads');
$model->tmp_name = time();
$model->file_type = $model->file->type;
$model->file_size = $model->file->size;
if ($model->save()) {
$model->file->saveAs(($dest . '/' . $model->tmp_name . '.' . $model->file->extensionName));
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array( 'model' => $model));
}
控制器:
array('file', 'file', 'on' => 'insert', 'maxSize'=> 512000, 'maxFiles'=> 1,
'mimeTypes' => 'application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/rtf, text/plain',
'tooLarge'=> 'File cannot be larger than 500KB.',
'wrongType'=> 'Format must be:<code>.doc</code>, <code>.docx</code>, <code>.txt</code>, <code>.rtf</code>'),
public function actionCreate() {
$model = new File;
if (isset($_POST['File'])) {
$model->setAttributes($_POST['File']);
// Set file
$model->file = CUploadedFile::getInstance($model,'file');
// Set directory
$dest = Yii::getPathOfAlias('application.uploads');
$model->tmp_name = time();
$model->file_type = $model->file->type;
$model->file_size = $model->file->size;
if ($model->save()) {
$model->file->saveAs(($dest . '/' . $model->tmp_name . '.' . $model->file->extensionName));
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array( 'model' => $model));
}
希望这对其他人有所帮助。启用扩展。你好,Mario,我刚刚检查了我的php.ini文件,它已经启用。错误消息是清除
文件或未找到路径
,因此加载了扩展名,但文件不存在。文件的可能副本已上载到正确的文件夹中。确定,这只是错误,不会将记录保存在数据库中。我确实将mimeType改回了“types”,同样的事情发生了,文件被正确上传,但是这次没有错误,但是没有记录被保存到数据库中。那么,问题是您的记录没有显示在数据库中,或者文件没有被保存,或者两者都没有?我认为解决您的DB保存问题会更干净,然后我们就可以解决这个问题。经过一些尝试和错误,将模型更改为“on”=>“insert”似乎有效,因为它保存了记录。该文件始终可以上载,但记录无法保存。现在,我可以让它保存在数据库中的记录,也在上传文件夹。我只保存了文本文件和.doc文件。目前,.docx文件不会保存,因为Yii声明它们不是可接受的mime类型。所以我明白你现在说的是喜怒无常。我仍然在使用规则中的'mimeType'键,而不是'types'键。-琼尼普。我发现,您必须向magic.mgc文件添加扩展以支持docx文件,这取决于您的PHP版本和基本操作系统。如果你需要帮助的话,做些调查然后回来怎么样。。。
public function actionCreate() {
$model = new File;
if (isset($_POST['File'])) {
$model->setAttributes($_POST['File']);
// Set file
$model->file = CUploadedFile::getInstance($model,'file');
// Set directory
$dest = Yii::getPathOfAlias('application.uploads');
$model->tmp_name = time();
$model->file_type = $model->file->type;
$model->file_size = $model->file->size;
if ($model->save()) {
$model->file->saveAs(($dest . '/' . $model->tmp_name . '.' . $model->file->extensionName));
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array( 'model' => $model));
}