public function executeUpload(sfWebRequest $request) { $result = 'All broken :('; try { //@todo: added CSRF check; $files = $request->getFiles(); $fileData = array_pop($files); $validator = new sfValidatorFile(array('max_size' => 1024 * 1024, 'mime_types' => array('image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif', 'application/octet-stream'))); $file = $validator->clean($fileData); $file instanceof sfValidatedFile; $uploader = new ImageUploader(); $uploaded = $uploader->login()->upload($file->getTempName()); $photo = new Photo(); $photo->name = $uploaded->image; $photo->thumb = $uploaded->thumb; $photo->save(); $result = array('id' => $photo->getId(), 'image' => $uploaded->image, 'thumb' => $uploaded->thumb); } catch (Exception $e) { $result = $e->getMessage(); } return $this->renderText(json_encode($result)); }