Hi all … I have very annoying problem. I have a table in database with just three fields:
TABLE : tbl_videos
id_vdo (Primary Key)
name_vdo varchar
file_vdo varchar
The problem is that when I insert record with File Vdo field set to "textField" everything works fine. As soon as I change it to file, the create form does not insert any record, neither it shows any error.
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new Videos;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Videos']))
{
$model->attributes=$_POST['Videos'];
$model->file_vdo = "test";
if($model->save())
$this->redirect(array('view','id'=>$model->id_vdo));
}
$this->render('create',array(
'model'=>$model,
));
}
Model Rules:
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('name_vdo, file_vdo', 'required'),
array('name_vdo', 'length', 'max'=>255),
array('file_vdo', 'file', 'types'=>'flv,mov,mp4'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id_vdo, name_vdo, file_vdo', 'safe', 'on'=>'search'),
);
}
Thank you so much jacmoe. But the problem is still there. I have already tried this:
public function actionCreate()
{
$model=new Videos;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Videos']))
{
$model->attributes=$_POST['Videos'];
$VideoFile = CUploadedFile::getInstance($model, 'file_vdo');
$VideoFile->saveAs(Yii::app()->basePath.'/../uploads/files/videos/currentvideo.mp4');
$model->file_vdo = $VideoFile;
if($model->save())
$this->redirect(array('view','id'=>$model->id_vdo));
}
$this->render('create',array(
'model'=>$model,
));
}
The problem is that the program control does get past the “if(isset($_POST[‘Videos’]))” condition. I have the exact similar table and its MVC structure and it works 100% fine. Not sure where is the problem.
I tried that too, even by copying the working code. I have a similar form for images and that works 100% perfect. I am not sure what the hell is with this.
The real problem is that it does get the "IF" condition passed. I tried one thing. I copied the form code from the source view and put it in a temporary PHP file. I replaced the action attribute value to post form to the current page for testing. The code is below:
Lets suppose you save the above code in temp.php. Now visit this file. You’ll notice that if you submit the form without selecting any File, it works 100% fine. However if you submit the form by selecting some file, it behaves the same way as my YII application.
It looks like we are getting close to the solution
Jacmoe, while working on the issue, I found that form works perfect if I set file types to JPG or PNG. However when I set file types to "flv, mp4", it stop working.
I finally got the problem but unable to know the reason . It simply does not accept flv and mp4 type files. Do you think it is related to my server configuration? If yes, please suggest some possible solutions. I tried by uploading mp4 type files with simple html form. I put the PHP code to die() when it sees the POST request. Even this simple form behave just like my Yii applicatin!!!
So in simple words, a form containing file field, does not support/handle mp4 and flv type files, atleast on my local server.
Does anyone ever see such problem? I wasted alot of hours on this.
Your problem might be happening because of the defined mime types in the /framework/utils/mimeTypes.php file.
Basically this file returns an array (key is the extension and the value is the mime type) and this array is searched later by YII to see if the file is valid.
However, some files might have multiple valid mime types, for example .tgz files can have application/x-tar but also application/x-gzip-compressed, zip files can have ‘application/x-zip’, ‘application/zip’, ‘application/x-zip-compressed’ and so on .
I know that the flash files might have distinct mime types, as specified here http://osflash.org/flv , so you might want to take a look there, and here http://www.feedforall.com/mime-types.htm and depending on this, you might find an answer to your question.
FYI: i will fill a feature request so that this file will be moved to the /config/ directory and to have the possibility to return an array of valid mime types.
Hi twisted, thanks for the reply. Can you please do a quick test? I attached very simple File upload form. It has no File Upload handler. The php code will simply call "die()" if it sees that form was submitted.
Try uploading FLV or MP4 file and please post here what you saw?