public function cropCoverPhoto($Croppath, $upload_id) { $uploader = new Utils_Uploader(array('jpeg', 'jpg', 'png')); $uploads = self::find($upload_id); $oldpath = $uploads->path; $oldname = $uploads->name; $uploadTypeModel = Model_Upload_Type::find($uploads->type_id); $typeName = $uploadTypeModel->types; if (file_exists($oldpath . $oldname)) { File::delete($oldpath . $oldname); } $img = $Croppath; $img = str_replace('data:image/png;base64,', '', $img); $img = str_replace(' ', '+', $img); $data = base64_decode($img); $file = $oldpath . "crop_image_" . $upload_id . ".png"; $original = $oldpath . $oldname; //$thumbnail = $path . 'min_' . $newFile; $success = file_put_contents($file, $data); //Image::load($file)->preset('coverimage')->save($thumbnail); //360 width Image::load($file)->preset($typeName)->save($original); //1260 width File::delete($file); return $oldname; }
public function removeFiles() { $uploadType = Model_Upload_Type::find($this->type_id); if ($uploadType->thumbnail == 1) { $thumbnail_path = DOCROOT . self::_THUMBNAIL_PATH; if (file_exists($thumbnail_path . $this->path)) { File::delete($thumbnail_path . $this->path); } } if (file_exists($this->path)) { File::delete($this->path); } DB::query("DELETE FROM `uploads` WHERE id='" . $this->id . "'")->execute(); }
public static function uploadPicture() { $join_id = Input::get('object_id'); $type = Input::get('object_type'); $user_id = Input::get('user_id'); $join_type = self::JOINTYPE_UPLOAD; $uploader = new Utils_Uploader(array('jpeg', 'jpg', 'png')); $path = DOCROOT . 'assets/uploads' . DS; if (!file_exists($path)) { mkdir($path, 0777, true); } $uploadTypeModel = Model_Upload_Type::find($type); $typeName = $uploadTypeModel->types; $pic_name = $typeName . "_" . time(); $original = $path . $pic_name; $output = $uploader->handleUploadRename($path, $pic_name); if (isset($output['success'])) { $original = $path . $output['full_filename']; $uploadAll = Model_Upload::forge(); $uploadAll->user_id = $user_id; $uploadAll->type_id = $type; $uploadAll->join_id = $join_id; $uploadAll->join_type = $join_type; $uploadAll->name = $output['full_filename']; $uploadAll->original_name = $output['full_filename']; #You can change this name to article name $uploadAll->path = $path; $uploadAll->save(); $output['upload_id'] = $uploadAll->id; if ($uploadTypeModel->crop == 0) { #If not set crop then preset other preset after crop Image::load($original)->preset($typeName)->save($original); } else { // Image::load($original)->preset('banner')->save($original); #check if height and width do not match } if (filesize($original) < 102400) { //Do nothing } else { if (filesize($original) < 524288) { self::compress($original, $original, 90); } elseif (filesize($original) < 1048576) { //1MB self::compress($original, $original, 75); } elseif (filesize($original) < 3145728) { //3MB self::compress($original, $original, 60); } elseif (filesize($original) < 6291456) { //6MB self::compress($original, $original, 40); } else { self::compress($original, $original, 30); } } $localFileName = $path . $output['full_filename']; $remoteFileName = DOCROOT . 'assets/uploads/' . DS . $output['full_filename']; $output['uri'] = Uri::create('upload/get_image/' . $output['full_filename'] . '/' . $output['upload_id']); } return $output; }