I'm using Yii to upload some files. And I'm getting the following error.
finfo_file() [<a href='function.finfo-file'>function.finfo-file</a>]: File or path not found 'C:\xampp\tmp\phpF48A.tmp'
I'm not sure exactly what it's from i've read around on the topic, I'm not sure I have the magic.mime database, do I need to get this and configure it? Or is the problem due to something else. This is the first time I've used Yii, so i'm not sure if it's just a config problem or what. This is the stack:
if($this->mimeTypes!==null)
221 {
222 if(function_exists('finfo_open'))
223 {
224 $mimeType=false;
225 if($info=finfo_open(defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME))
226 $mimeType=finfo_file($info,$file->getTempName());
227 }
Any help, greatly appreciated it. To add, the file is saved in the correct directory, it records aren't saved in the DB though.
Thanks
Jonny
Updated code
Model
array('file', 'file', 'allowEmpty' => false, 'maxSize'=> 512000, 'maxFiles'=> 1,
'mimeTypes' => 'application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/rtf, text/plain',
Controller (Pretty much the default Gii 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->saveAs(($dest . '/' . $model->tmp_name . '.' . $model->file->extensionName));
if ($model->save()) {
} else {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array( 'model' => $model));
}