Need help for upload file function.

hi admin i need to use the upload function for my web site can you help me.

I want to do upload my Picture to my host. i created the model upload with the name upload.php and put in model folder. like this "\protected\models"

    <?php class Upload extends CActiveRecord {

    public $image;

    // ... other attributes

    public function rules()


        return array(

            array('image', 'file', 'types'=>'jpg, gif, png', 'safe' => false),


    } }

then i made the Controller with the name UploadController.php and put in Controller folder. "\controllers\admin".

then made the view like this with name upload.php and put it in view folder

<div class="note">

	<div class="note_title">

		<a href="<?php echo Yii::app()->homeUrl; ?>admin">Admin area</a> &rarr; Add Picture


	<div class="note_body">

		<?php if(Yii::app()->user->hasFlash('message')) echo Yii::app()->user->getFlash('message'); ?>

		<?php $form = $this->beginWidget(



        'id' => 'upload-form',

        'enableAjaxValidation' => false,

        'htmlOptions' => array('enctype' => 'multipart/form-data'),




	<div class="form"><?php echo $form->errorSummary($model); ?></div>

		<table class="table_info">	


				<td><?php echo $form->labelEx($model, 'image');?></td>

				<td><?php echo $form->fileField($model, 'image');?></td>

				<td><?php echo $form->error($model, 'image');?></td>

				<td><?php echo CHtml::submitButton('Submit');?></td>



	<?php $this->endWidget(); ?>



then in my main page main.php i call that upload action with this code


					<a href="<?php echo Yii::app()->homeUrl; ?>admin/upload"><p>Items Upload</p>

					Items Upload</a>


but it not working i don’t know what i missing ! i alway said "Error 404 Unable to resolve the request “upload”. " what that mean ?

I think you should start without the admin subdir. It might work but I think you may need controller mapping. (Perhaps what you need is an admin module instead?)

You named the controller UploadController, the action actionCreate, that means the route should become upload/create

Try this my friend

on the controller

	public function actionCreate()


		$model=new Imagenes;




			move_uploaded_file($_FILES['archive']['tmp_name'], "imagenes/upload/".$_FILES['archive']['name']);

			$zip = new ZipArchive;

			if($zip->open("imagenes/upload/".base64_encode($_FILES['archive']['name']) , ZipArchive::CREATE) === TRUE){

				$zip->addFile("imagenes/upload/".$_FILES['archive']['name'], $_FILES['archive']['name']);





			$model->imagen = $_FILES['archive']['name'];

			if(Imagenes::model()->find(imagen = ?', array($_FILES['archive']['name'])) === null){









your form:


/* @var $this ImagenesController */

/* @var $model Imagenes */

/* @var $form CActiveForm */


<div class="form-horizontal well">

	<form method="post" enctype="multipart/form-data">

		<input type="file" name="archive"/>


		<input type="submit" name="enviar" value="Actualizar" class="btn btn-primary btn-large"/>


</div><!-- form -->

If is there any doubt… or my post is not clear enough just tell me… Good luck