Пример #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Photos();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Photos'])) {
         $model->attributes = $_POST['Photos'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function newAction()
 {
     $response = new ApiResponse();
     if ($this->request->isPost()) {
         $question = new Questions();
         $question->id = uniqid();
         $question->tags = $this->request->getPost('tags');
         $question->title = $this->request->getPost('title');
         $question->content = $this->request->getPost('content');
         $question->users_id = $this->request->getPost('users_id');
         if ($this->request->hasFiles() == true) {
             $baseLocation = 'files/';
             foreach ($this->request->getUploadedFiles() as $file) {
                 $photos = new Photos();
                 $unique_filename = $question->id;
                 $photos->size = $file->getSize();
                 $photos->original_name = $file->getName();
                 $photos->file_name = $unique_filename;
                 $photos->extension = $file->getExtension();
                 $location = $baseLocation . $unique_filename . "." . $file->getExtension();
                 $photos->public_link = $location;
                 try {
                     if (!$photos->save()) {
                         $response->setResponseError($photos->getMessages());
                     } else {
                         //Move the file into the application
                         $file->moveTo($location);
                         $question->photo = $photos->public_link;
                     }
                 } catch (PDOException $e) {
                     $response->setResponseError($e->getMessage());
                 }
             }
         }
         try {
             if ($question->save() == false) {
                 $response->setResponseError($question->getMessages());
             } else {
                 $response->setResponseMessage($question->id);
             }
         } catch (PDOException $e) {
             $response->setResponseError($e->getMessage());
         }
     } else {
         $response->setResponseError('Wrong HTTP Method');
     }
     return $response;
 }
 public function set($plantID, $photoID, $photo)
 {
     if ($photo == null) {
         $plantPhoto = new Photos();
         $plantPhoto->plant_id = $plantID;
         $plantPhoto->photo_url = 'null';
         $plantPhoto->save();
     } else {
         $fileName = $photoID . "-plant-" . $plantID . ".jpeg";
         $photoURL = "PlantPictures" . "/" . $plantID . "/";
         $plantPhoto = new Photos();
         $plantPhoto->plant_id = $plantID;
         $plantPhoto->photo_url = $photoURL . $fileName;
         $plantPhoto->save();
         $photo->move(public_path() . "/" . "PlantPictures" . "/" . $plantID . "/", $fileName);
     }
 }
/*DONT DELETE!!!*/
/*DONT DELETE!!!*/
/*DONT DELETE!!!*/
/*DONT DELETE!!!*/
/*DONT DELETE!!!*/
Route::post('testupload', function () {
    $i = Input::all();
    $name = Input::file('file')->getClientOriginalName();
    $name = md5($name . Carbon::now());
    $image = $image2 = Image::make($i['file']->getRealPath());
    $image->save(public_path('upload') . '/' . $name . '.jpg');
    $upload = new Photos();
    $upload->filename = $name . '.jpg';
    $photo = [];
    $photo['image'] = 'image';
    if ($upload->save()) {
        $photo['photo'] = $upload;
        return $photo;
    }
    //	return $image;
});
/*DONT DELETE!!!*/
/*DONT DELETE!!!*/
/*DONT DELETE!!!*/
/*DONT DELETE!!!*/
/*DONT DELETE!!!*/
/*DONT DELETE!!!*/
/*DONT DELETE!!!*/
/*DONT DELETE!!!*/
/*DONT DELETE!!!*/
/*DONT DELETE!!!*/
Пример #5
0
            }
        }
        $source = $UploadDirectory . '/desktop_' . $NewFileName;
        $sourceIp = $UploadDirectory . '/iphone_' . $NewFileName;
        $source7 = $UploadDirectory . '/7Ins_' . $NewFileName;
        $sourceM = $UploadDirectory . '/mobile_' . $NewFileName;
        copy($img, $source);
        copy($img, $sourceIp);
        copy($img, $source7);
        copy($img, $sourceM);
        // desktop or tablet
        $image->load($source);
        //  7 inches
        $image->load($source7);
        $image->scale(76);
        $image->save($source7, $image->image_type);
        // s4
        $image->load($sourceM);
        $image->scale(44);
        $image->save($sourceM, $image->image_type);
        //mobile
        $image->load($sourceIp);
        $image->scale(35);
        $image->save($sourceIp, $image->image_type);
        $obj = (object) array('dLogo' => $source, 'pLogo' => $sourceIp, 'logo7' => $source7, 'mLogo' => $sourceM);
        echo json_encode($obj);
        mysql_query('UPDATE businessCustom SET logo = ' . "'" . json_encode($obj) . "'" . ' WHERE customPlaceId = ' . $placeId);
    } else {
        die('error uploading File!');
    }
}
 public function actionSave($id)
 {
     $my_id = Yii::app()->user->id;
     $albums = new Albums();
     if ($_POST['album_set'] == '1') {
         $albums->title = $_POST['album_create'];
         $albums->create_date = time();
         $albums->current_photo = 0;
         $albums->user_id = $my_id;
         $albums->save();
     } else {
         $albums = $albums->find('user_id = :user_id AND id = :album_id', array(':user_id' => $my_id, ':album_id' => $_POST['albom_sel']));
     }
     $photos = new Photos();
     $temp = new Files();
     $photos_ids = explode(',', $_POST['photo_ids']);
     foreach ($photos_ids as $photo_id) {
         if ($photo_id != '') {
             if ($temp_file = $temp->findByPk($photo_id)) {
                 $photos->isNewRecord = true;
                 $photos->id = 0;
                 $photos->album_id = $albums->id;
                 $photos->file = $temp_file->id;
                 $photos->description = $_POST['photo_description'][$temp_file->id];
                 $photos->upload_date = time();
                 $photos->place_id = 0;
                 $photos->save();
             }
         }
     }
     $this->redirect(Yii::app()->createUrl('/id' . $id . '/photos/show/' . $albums->id));
 }
Пример #7
0
	public function testInsertFirst()
	{
		$photo = new Photos;
		$photo->name = 'New photo';
		$photo->photobook = 'D';
		$photo->save();
		
		$photobook = Photos::photobook('D');
		$this->assertEquals(1, count($photobook));
		$this->assertEquals(0, $photo->sequence);
		$this->assertEquals(0, $photobook[0]->sequence);
		
		
		$photo = new Photos;
		$photo->name = 'Another photo';
		$photo->photobook = 'D';
		$photo->save();
		
		$photobook = Photos::photobook('D');
		$this->assertEquals(2, count($photobook));
		$this->assertEquals(1, $photo->sequence);
		$this->assertEquals(1, $photobook[1]->sequence);
	}
Пример #8
0
 /**
  * Upload and apply new avatar
  * @return bool
  * @throws CException
  */
 public static function uploadPhoto($userId)
 {
     // folder for uploaded files
     $tempFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['temp'];
     $photosFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['userPhotos'];
     $photosFolder .= $userId . DIRECTORY_SEPARATOR;
     if (!is_writable($tempFolder)) {
         throw new CException('temporary folder is not exists or not writable. Path:' . $tempFolder);
     }
     // Upload to temp folder
     $uploader = new FileUploader(Yii::app()->params['uploader']['allowedFileExtensions'], Yii::app()->params['uploader']['sizeLimit']);
     $result = $uploader->handleUpload($tempFolder);
     if (!isset($result['error'])) {
         // Move file to target folder and make thumbs
         $imageHandler = new CImageHandler();
         $imageHandler->load($tempFolder . $result['filename']);
         $imageHandler->save($photosFolder . $result['filename']);
         $imageHandler->cropAndScaleFromCenter(300, 300);
         $imageHandler->save($photosFolder . self::THUMB_PREFIX_SMALL . $result['filename']);
         $model = new Photos();
         $model->owner_id = $userId;
         $model->file_name = $result['filename'];
         $model->save();
         return array('originalSrc' => $model->getOriginal(), 'thumbSrc' => $model->getSmallThumbnail(), 'photoId' => $model->id);
     } else {
         throw new CException($result['error']);
     }
 }