I am trying to upload video.I have write following code.
In Model
[['videoFile'], 'file','extensions' => 'mp4','maxFiles' => 1],
In View ,
<?= $form->field($model, 'videoFile')->fileInput()->label(false) ?>
In controller ,
$model->videoFile = UploadedFile::getInstance($model, 'videoFile');
print_r($model->videoFile);exit;
But continuously facing following problem
Array ( [0] => yii\\web\\UploadedFile Object ( [name] => SampleVideo_1280x720_2mb.mp4 [tempName] => [type] => [size] => 0 [error] => 1 ) )
Here tempName is empty and [error] => 1.
Any idea what I am doing wrong. How can we show uploadFile error here.
Thanks
temppath(server tempary store path) not found that why you get error
like xampp server path store (C:\\xampp\\tmp) this location store tempary file
Try to uplaod by this way :
if(isset($_FILES['videoFile']['tmp_name']) && $_FILES['videoFile']['tmp_name'] != null)
{
$file = $_FILES;
$model->videoFile = "YourPath/".$file['videoFile']['name'];
move_uploaded_file($file['videoFile']['tmp_name'],"YourPath/".$model->videoFile);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.