Yii file upload issue
Posted
by
user1289853
on Stack Overflow
See other posts from Stack Overflow
or by user1289853
Published on 2012-03-24T11:07:59Z
Indexed on
2012/03/24
17:29 UTC
Read the original article
Hit count: 191
Couple of months ago,I developed a simple app using YII,one of the feature was to upload file. The feature was working well in my dev machine,couple of days ago client found the file upload feature is not working in his server since deployment.
And after that I test my dev machine that was not working too.
My controller looks:
public function actionEntry() {
if (!Yii::app()->user->isGuest) {
$model = new TrackForm;
if (isset($_POST['TrackForm'])) {
$entry = new Track;
try {
$entry->product_image = $_POST['TrackForm']['product_image'];
$entry->product_image = CUploadedFile::getInstance($model, 'product_image');
if ($entry->save()) {
if ($entry->product_image) {
$entry->product_image->saveAs($entry->product_image->name, '/trackshirt/uploads');
}
}
$this->render('success', array('model' => $model));
// redirect to success page
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
} else {
$this->render('entry', array('model' => $model));
}
}
}
Model is like below:
<?php
class Track extends CActiveRecord
{
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'product_details';
}
}
My view looks:
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'hide-form',
'enableClientValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
),
'htmlOptions' => array('enctype' => 'multipart/form-data'),
));
?>
<p class="auto-style2"><strong>Administration - Add New Product</strong></p>
<table align="center" style="width: 650px"><td class="auto-style3" style="width: 250px">Product Image</td>
<td>
<?php echo $form->activeFileField($model, 'product_image'); ?>
</td>
</tr>
</table>
<p class="auto-style1">
<div style="margin-leftL:-100px;">
<?php echo CHtml::submitButton('Submit New Product Form'); ?>
</div>
<?php $this->endWidget(); ?>
Any idea where is the problem?I tried to debug it but every time it returns Null.
Thanks.
© Stack Overflow or respective owner