Hi,
I’m am using CUploadedFile::getInstance to upload a image, but it always return null. here’s my code:
On controller:
if (isset($_POST['Mestre'])) {
$model->attributes = $_POST['Mestre'];
$file = CUploadedFile::getInstance($model, 'fotografia');
if ($file === null) {
echo '<script> console.log("print_r($_FILES) = ' . print_r($_FILES) . '")</script>'; //what is printed here is a '1' on the console and an empty array on the screen..
}
On view:
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'mestre-form',
'enableClientValidation' => true,
'enableAjaxValidation' => false,
'htmlOptions' => array(
'enctype' => 'multipart/form-data',
),
));
?>
........
<div class="row">
<?php echo $form->labelEx($model, 'fotografia'); ?>
<?php echo $form->fileField($model, 'fotografia'); ?>
<?php echo $form->error($model, 'fotografia'); ?>
</div>
On Model:
I added a variable $fotografia, and add the folowing rule:
array('fotografia', 'file', 'types' => 'jpg, gif, png', 'allowEmpty' => true, 'on'=>'update'),
I previously could upload the foto, but, I don’t know why (in my point of view, I’ve not made any significant change, jus the form is now loaded by ajax request) it’s not working.
What I’m doing wrong?
Please help me. I’m struggling with that for the past two days…