yii2得到上传本地文件的文件路径
问题描述:
我想请教一下如何让我想从文件输入上传文件的文件路径,代码是这样的yii2得到上传本地文件的文件路径
<?= $form->field($model, 'file')->fileInput() ?>
问题是我想自动发送该文件作为电子邮件附件的不将文件上传到主机,这需要
->attach('C:/Users/User/Downloads/file/file.pdf')
我想得到这样
'C:/Users/User/Downloads/file/file.pdf'
文件路径本地文件的路径
有可能吗?或者有另一种方法来解决我的问题? 在此先感谢
答
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.
}
+0
后期更新抱歉,它的工作,但我已经使用这个问题的一些代码https://*.com/questions/46660315/yii2-form-to-send-attachment ,谢谢 –
看看这个类似的问题 - https://*.com/questions/857618/javascript-how-to-extract-filename-from-a-file-input-control –
好吧,试图用java脚本,我会稍后更新结果 –
检查yii2文档:'http:// www.yiiframework.com/doc-2.0/yii-web-uploadedfile.html' – Kalu