hello guys, my upload code is failing to send data to the database,my cod is as follows:
The Controller:
<?php
class UploadController extends Controller
{
function actionIndex()
{
$dir = Yii::getPathOfAlias('q5394727.uploads');
$uploaded = false;
$model=new Upload();
if(isset($_POST['Upload']))
{
$model->attributes=$_POST['Upload'];
$file=CUploadedFile::getInstance($model,'file');
if($model->validate()){
$uploaded = $file->saveAs($dir.'q5394727.upload'.$file->getName());
//$uploaded=$file->saveAs(Yii::app()->basePath.$fileName);
}
}
$this->render('index', array(
'model' => $model,
'uploaded' => $uploaded,
'dir' => $dir,
));
}
}
THE MODEL:
<?php
class Upload extends CFormModel
{
public $file;
public function rules()
{
return array(
array('file', 'file', 'types'=>'docx', 'allowEmpty'=>true, 'on'=>'insert,update'),
);
}
}
THE VIEW:
<?php
/* @var $this UploadController */
$this->breadcrumbs=array(
'Upload',
);
?>
<h1><?php echo $this->id . ‘/’ . $this->action->id; ?></h1>
<?php if($uploaded):?>
<p>File was uploaded. Check <?php echo $dir?>.</p>
<?php endif ?>
<?php echo CHtml::beginForm(’’,‘post’,array(‘enctype’=>‘multipart/form-data’))?>
<?php echo CHtml::error($model, ‘file’)?>
<?php echo CHtml::activeFileField($model, ‘file’)?>
<?php echo CHtml::submitButton(‘Upload’)?>
<?php echo CHtml::endForm()?>
<p>
You may change the content of this page by modifying
the file <tt><?php echo __FILE__; ?></tt>.
</p>
HOW AM I SUPPOSED TO SPECIFY THE PATH?
I TRIED THIS CODE ON THE LOCAL SERVER AND ON THE ONLINE SERVER. PLEASE HELP