PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 28, 2022

[FIXED] yii get filetype and filesize of the file upload-

 February 28, 2022     file, size, types, upload, yii     No comments   

Issue

I need help to get file and type of the file which i upload.

My controller is next:

public function actionUpload()
    {
        $model=new Entryfile;
        $exstansion = Extansion::model()->findAll();
        $some = array();
        foreach ($exstansion as $key=>$value)
        $some[$value->idExt]=$value->ExtansionName;
        if(isset($_POST['Entryfile'])) {
             $model->attributes=$_POST['Entryfile'];
             //$model->uUserID = $_POST['User']['uUserID'];
             //Yii::import('ext.helpers.EDownloadHelper'); 
             //EDownloadHelper::download(Yii::getPathOfAlias('dms.upload').DIRECTORY_SEPARATOR.'name');
             $model->eeFileName=CUploadedFile::getInstance($model,'eeFileName');
             if($model->save()) {
                 $model->eeFileName->saveAs('upload/'.$model->eeFileName->name);
                 $this->redirect(array('view','id'=>$model->eeEntryFileID));
             }
        }
        $this->render('upload',array('model'=>$model, 'exstansion'=>$some));
    }

I need solution for file size and file type. I want to save file and size in database table. But I need step by step instruction, in code if it is possible.


Solution

You can get the file size by getSize() method:

$size=$model->eeFileName->getSize();

and you can get file type by using getType():

$type=$model->eeFileName->getType();

For more information check the CUploadedFile Documents.



Answered By - Ali MasudianPour
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing