Search code examples
phpyiiyii2yii-components

yii2 get filepath of the uploaded local file


I want to ask about how to get the file path of the file i want to upload from file input, the code is like this

<?= $form->field($model, 'file')->fileInput() ?>

the problem is i want to automatically send the file as attachment of email without uploading the file to hosting, which required the path of local file

 ->attach('C:/Users/User/Downloads/file/file.pdf')

I want to get file path like

'C:/Users/User/Downloads/file/file.pdf'

is it possible? or there is another method to fix my problem? Thanks in advance


Solution

  • Check yii2 doc. [http://www.yiiframework.com/doc-2.0/yii-web-uploadedfile.html]
    if (Yii::$app->request->isPost) {
           $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
           $tempFilePath = $model->imageFile->tempName;
           //Send Email.
        }