protected function _actionAdd($context)
    {
        $data = $context->data;
        $file = AnRequest::get('files.file', 'raw');
        $content = @file_get_contents($file['tmp_name']);
        $filesize = strlen($content);
        $uploadlimit = $this->_max_upload_limit * 1024 * 1024;

        $exif = (function_exists('exif_read_data')) ? @exif_read_data($file['tmp_name']) : array();

        if ($filesize == 0) {
            throw new LibBaseControllerExceptionBadRequest('File is missing');

            return;
        }

        if ($filesize > $uploadlimit) {
            throw new LibBaseControllerExceptionBadRequest('Exceed maximum size');

            return;
        }

        $orientation = 0;

        if (!empty($exif) && isset($exif['Orientation'])) {
            $orientation = $exif['Orientation'];
        }

        $data['portrait'] = array(
            'data' => $content,
            'rotation' => $orientation,
            'mimetype' => isset($file['type']) ? $file['type'] : null,
        );

        $photo = $this->actor->photos->addNew($data);
        $photo->setExifData($exif);
        $photo->save();
        $this->setItem($photo);
        $this->getResponse()->status = AnHttpResponse::CREATED;

        if ($photo->body && preg_match('/\S/', $photo->body)) {
            $context->append(array(
                'story' => array('body' => $photo->body),
            ));
        }

        return $photo;
    }
protected function _actionAdd($context)
    {
        $data = $context->data;
        $file = AnRequest::get('files.file', 'raw');
        $content = @file_get_contents($file['tmp_name']);
        $filesize = strlen($content);
        $uploadlimit = $this->_max_upload_limit * 1024 * 1024;

        $exif = (function_exists('exif_read_data')) ? @exif_read_data($file['tmp_name']) : array();

        if ($filesize == 0) {
            throw new LibBaseControllerExceptionBadRequest('File is missing');

            return;
        }

        if ($filesize > $uploadlimit) {
            throw new LibBaseControllerExceptionBadRequest('Exceed maximum size');

            return;
        }

        $orientation = 0;

        if (!empty($exif) && isset($exif['Orientation'])) {
            $orientation = $exif['Orientation'];
        }

        $data['portrait'] = array(
            'data' => $content,
            'rotation' => $orientation,
            'mimetype' => isset($file['type']) ? $file['type'] : null,
        );

        $photo = $this->actor->photos->addNew($data);
        $photo->setExifData($exif);
        $photo->save();
        $this->setItem($photo);
        $this->getResponse()->status = AnHttpResponse::CREATED;

        if ($photo->body && preg_match('/\S/', $photo->body)) {
            $context->append(array(
                'story' => array('body' => $photo->body),
            ));
        }

        return $photo;
    }
protected function _actionAdd ( $ context ) { $ data = $ context -> data ; $ file = AnRequest :: get ( 'files.file' , 'raw' ) ; $ content = @ file_get_contents ( $ file [ 'tmp_name' ] ) ; $ filesize = strlen ( $ content ) ; $ uploadlimit = $ this -> _max_upload_limit * 1024 * 1024 ; $ exif = ( function_exists ( 'exif_read_data' ) ) ? @ exif_read_data ( $ file [ 'tmp_name' ] ) : array ( ) ; if ( $ filesize == 0 ) { throw new LibBaseControllerExceptionBadRequest ( 'File is missing' ) ; return ; } if ( $ filesize > $ uploadlimit ) { throw new LibBaseControllerExceptionBadRequest ( 'Exceed maximum size' ) ; return ; } $ orientation = 0 ; if ( ! empty ( $ exif ) && isset ( $ exif [ 'Orientation' ] ) ) { $ orientation = $ exif [ 'Orientation' ] ; } $ data [ 'portrait' ] = array ( 'data' => $ content , 'rotation' => $ orientation , 'mimetype' => isset ( $ file [ 'type' ] ) ? $ file [ 'type' ] : null , ) ; $ photo = $ this -> actor -> photos -> addNew ( $ data ) ; $ photo -> setExifData ( $ exif ) ; $ photo -> save ( ) ; $ this -> setItem ( $ photo ) ; $ this -> getResponse ( ) -> status = AnHttpResponse :: CREATED ; if ( $ photo -> body && preg_match ( '/\S/' , $ photo -> body ) ) { $ context -> append ( array ( 'story' => array ( 'body' => $ photo -> body ) , ) ) ; } return $ photo ; }
Method to upload and Add a photo.

@param AnCommandContext $context
Method to upload and Add a photo .