Add Image Upload To A Form

Let’s say I have a model called X with a simple form with 2 imputs, a title and a description. Now I want to add a new imput to upload an image, save it into a folder and rename it.

I’ve followed a few tutorials but I can’t make this work correctly.

Any ideas?

Thanks

EDIT: it would be nice to save the image url into the database

Have you try this wiki?

Yes, but that’s a model only for images. If I don’t find anything else I think I’ll do something like that but it isn’t what I’m looking for.

EDIT: I managed to make it work.

¿How can I resize the image now?

try this ex…




if ((isset($_FILES['VenueEvent']['name']['event_flyer_image'])) && ($_FILES['VenueEvent']['name']['event_flyer_image'] != '')) {

   			$model->event_flyer_image = CUploadedFile::getInstance($model, 'event_flyer_image');

   		$model->event_flyer_image->saveAs('upload/event/' . $model->event_flyer_image);

}