Hi everybody!
i follwed and searched all topics about file uploading. But I can’t get it working at my project. I allways get error message below:
move_uploaded_file(/YiiLearning/data/long.txt) [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open stream: No such file or directory .
My model
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('title', 'required'),
array('title', 'length', 'max'=>150),
array('filename','file','types'=>'png,txt','wrongType'=>"Sai thuoc tinh"),
array('file', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, filename, title', 'safe', 'on'=>'search'),
);
}
my Controller
public function actionUpload()
{
$cssfile = Yii::app()->baseUrl.'/css/uploadfile/uploadfileform.css';
Yii::app()->clientScript->registerCssFile($cssfile);
$file = new FileModel();
if(isset($_POST['FileModel']))
{
$file -> attributes = $_POST['FileModel'];
$upload = CUploadedFile::getInstance($file,'filename');
$upload->saveAs(Yii::app()->baseUrl.'/data/'.$upload->name);
}
$this->render('Upload',array('file'=>$file));
}
My View
<?php
$this->breadcrumbs=array(
'Upload File'=>array('uploadFile/index'),
'Upload',
);
Yii::app()->clientScript->registerCoreScript('jquery');
?>
<h1>File Upload</h1>
<div id='form'>
<?php
$form=$this->beginWidget('CActiveForm',
array(
'id'=>'frmUploadFile',
'htmlOptions' => array(
'enctype' => "multipart/form-data",
)
));
?>
<div class ='row'>
<?php
echo Chtml::activeLabel($file, 'title');
echo CHtml::activeTextField($file, 'title');
echo CHtml::error($file, 'title');
?>
</div>
<div class ='row'>
<?php
echo Chtml::activeLabel($file, 'filename');
echo Chtml::activeFileField($file, 'filename');
echo CHtml::error($file, 'filename');
?>
</div>
<div class='rowButton'>
<?php
echo Chtml::submitButton('Send File');
?>
</div>
<?php
$this->endWidget();
?>
</div>
Cuploadedfile is too hard to me to use.
----Thank—