hi everyone,i’m new in YII and i need your help,
i want upload my excel file with php excel reader extension,
my view/upload code
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'upload-form',
'enableAjaxValidation'=>false,
'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>
<div class="row">
<b>Masukkan Formulir :</b>
<?php echo $form->fileField($model,'filee',array('size'=>60,'maxlength'=>200)); ?>
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget(); ?>
</div>
and then in my model/dataLksa
public $filee;
...
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('kode_lksa, nama_lksa, alamat, email, pimpinan, status_kepemilikan_id, contact_person, no_hp, jumlah_anak, akta_notaris, NPWP, sip, bank, nama_dalam_rekening, no_rekening', 'required'),
array('kabupaten_id, provinsi_id, status_kepemilikan_id', 'numerical', 'integerOnly' => true),
array('kode_lksa, nama_lksa, alamat, email, pimpinan, contact_person, no_hp, jumlah_anak, akta_notaris, NPWP, sip, bank, nama_dalam_rekening, no_rekening', 'length', 'max' => 45),
array('filee', 'file', 'types' => 'xls'),
array('filee', 'safe', 'on' => 'upload'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, kode_lksa, nama_lksa, alamat, kabupaten_id, provinsi_id, email, pimpinan, status_kepemilikan_id, contact_person, no_hp, jumlah_anak, akta_notaris, NPWP, sip, bank, nama_dalam_rekening, no_rekening', 'safe', 'on' => 'search'),
);
}
...
and for actionUpload
public function actionUpload()
{
$model=new DataLksa;
if(isset($_POST['DataLksa']))
{
$model->attributes=$_POST['DataLksa'];
$itu=CUploadedFile::getInstance($model,'filee');
$path='/../Formulir_LKSA.xls';
$itu->saveAs($path);
$data = new Spreadsheet_Excel_Reader($path);
$id=array();
$nama=array();
for ($j = 4; $j <= $data->sheets[0]['numCells']; $j++)
{
$kode_lksa=$data->sheets[0]['cells'][5][$j];
$nama_lksa=$data->sheets[0]['cells'][6][$j];
$alamat=$data->sheets[0]['cells'][7][$j];
$kabupaten_id=$data->sheets[0]['cells'][8][$j];
$provinsi_id=$data->sheets[0]['cells'][9][$j];
$email=$data->sheets[0]['cells'][10][$j];
$pimpinan=$data->sheets[0]['cells'][11][$j];
$status_kepemilikan=$data->sheets[0]['cells'][12][$j];
$contact_person=$data->sheets[0]['cells'][13][$j];
$no_hp=$data->sheets[0]['cells'][14][$j];
$jumlah_anak=$data->sheets[0]['cells'][15][$j];
$akta_notaris=$data->sheets[0]['cells'][16][$j];
$npwp=$data->sheets[0]['cells'][17][$j];
$sip=$data->sheets[0]['cells'][18][$j];
$bank=$data->sheets[0]['cells'][19][$j];
$nama_dalam_rekening=$data->sheets[0]['cells'][20][$j];
$no_rekening=$data->sheets[0]['cells'][21][$j];
}
for($i=0;$i<count($id);$i++)
{
$model=new Upload;
$model->id=$id[$i];
$model->nama=$keg[$i];
$model->save();
}
unlink($path);
$this->redirect(array('index'));
}
$this->render('upload',array('model'=>$model));
}
i got error
move_uploaded_file(/../Formulir_LKSA.xls) [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open stream: Permission denied
if i change $path=’/../Formulir_LKSA.xls’; to $path=‘f:\Formulir_LKSA.xls’;
i got
include(Spreadsheet_Excel_Reader.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
please help me