I want to know how to get a value of object. I am using Yii framework for imeplement a download function. How to pass a parameter from frontend
I printed out a object, but I don't know how to get a value from this object.
Array
(
[file] => CUploadedFile Object
(
[_name:CUploadedFile:private] => 23602414.pdf
[_tempName:CUploadedFile:private] => D:\wamp\tmp\php8780.tmp
[_type:CUploadedFile:private] => application/pdf
[_size:CUploadedFile:private] => 181004
[_error:CUploadedFile:private] => 0
[_e:CComponent:private] =>
[_m:CComponent:private] =>
)
[layout] => //layouts/column1
[menu] => Array
(
)
[breadcrumbs] => Array
(
)
[defaultAction] => index
[_widgetStack] => Array
(
)
)
I want to get the "23602414.pdf", and store it to a varable.
This is my code.
<?php $model=new Upload(); ?>
<?php if(isset($_POST['Upload'])){$model->attributes=$_POST['Upload'];
$this->file=CUploadedFile::getInstance($model,'file');
}?>
<?php echo CHtml::link('Download file',array('/upload/download','id'=>'23602414.pdf')); ?>
Instead of hard code as 'id'=>'23602414.pdf', I want to echo the file name in there.
try this
Documentation here https://www.yiiframework.com/doc/api/1.1/CUploadedFile
I rewrited my code like below:
My model:
My controller:
My view:
refer:PHP getName() Function