本文整理匯總了PHP中Images::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP Images::save方法的具體用法?PHP Images::save怎麽用?PHP Images::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Images
的用法示例。
在下文中一共展示了Images::save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: uploadDocuments
/**
* Upload documents
* @param $uploadType
* @param bool $withoutMessage
* @return int
*/
public static function uploadDocuments($uploadType, $withoutMessage = false) {
if(isset($_SESSION[$uploadType]) && count($_SESSION[$uploadType]) > 0) {
$settings = UsersSettings::model()->findByAttributes(array(
'User_ID' => Yii::app()->user->userID,
));
//get default bank account
$condition = new CDbCriteria();
$condition->condition = "users_project_list.User_ID = '" . Yii::app()->user->userID . "'";
$condition->addCondition("users_project_list.Client_ID = '" . Yii::app()->user->clientID . "'");
$condition->addCondition("t.Account_Num_ID = '" . $settings->Default_Bank_Acct . "'");
$condition->join = "LEFT JOIN projects ON projects.Project_ID = t.Project_ID
LEFT JOIN users_project_list ON users_project_list.Project_ID = t.Project_ID";
$bankAcct = BankAcctNums::model()->with('client.company', 'project')->find($condition);
$defaultBankAcct = 0;
if ($bankAcct) {
$defaultBankAcct = $settings->Default_Bank_Acct;
}
//get user to send email
$person_to_email = false;
if (Yii::app()->user->id != 'user' && Yii::app()->user->id != 'single_user') {
$person_to_email = Users::model()->with('person')->findByPk(Yii::app()->user->userID);
} else {
$condition = new CDbCriteria();
$condition->join = "LEFT JOIN users_client_list ON users_client_list.User_ID = t.User_ID";
$condition->addInCondition('users_client_list.User_Type', array(UsersClientList::APPROVER, UsersClientList::PROCESSOR, UsersClientList::CLIENT_ADMIN));
$condition->addInCondition('t.User_Type', array(Users::ADMIN, Users::DB_ADMIN, Users::DATA_ENTRY_CLERK), "OR");
$condition->addCondition("users_client_list.Client_ID = '" . Yii::app()->user->clientID . "'");
$person_to_email = Users::model()->with('person')->find($condition);
}
foreach ($_SESSION[$uploadType] as $key => $current_upload_file) {
// check fed id
if ($current_upload_file['doctype'] == self::W9) {
if (!preg_match('/^(\d{2}\-\d{7})|(\d{3}\-\d{2}\-\d{4})|(IN[-]\d{6})|(T0[-]\d{7})$/', $current_upload_file['fed_id'])) {
return 2;
}
}
}
// insert documents into DB
foreach ($_SESSION[$uploadType] as $key => $current_upload_file) {
if (file_exists($current_upload_file['filepath'])) {
// create document
$document = new Documents();
$document->Document_Type = $current_upload_file['doctype'];
$document->User_ID = Yii::app()->user->userID;
$document->Client_ID = Yii::app()->user->clientID;
$document->Project_ID = Yii::app()->user->projectID;
$document->Created = date("Y-m-d H:i:s");
$document->save();
$new_doc_id=$document->Document_ID;
Audits::LogAction($document->Document_ID ,Audits::ACTION_UPLOAD);
// insert image
$image = new Images();
$imageData = addslashes(fread(fopen($current_upload_file['filepath'],"rb"),filesize($current_upload_file['filepath'])));
//$imageData = FileModification::ImageToPdfByFilePath($current_upload_file['filepath']);
$image->Document_ID = $document->Document_ID;
$image->Img = $imageData;
$image->File_Name = $current_upload_file['name'];
$image->Mime_Type = $current_upload_file['mimetype'];
$image->File_Hash = sha1_file($current_upload_file['filepath']);
$image->File_Size = intval(filesize($current_upload_file['filepath']));
$image->Pages_Count = FileModification::calculatePagesByPath($current_upload_file['filepath']);
$image->save();
$infile = @file_get_contents($current_upload_file['filepath'], FILE_BINARY);
if (($current_upload_file['mimetype'] == 'application/pdf' && $image->findPdfText($infile) == '')
|| $current_upload_file['mimetype'] != 'application/pdf') {
Documents::crateDocumentThumbnail($current_upload_file['filepath'], 'thumbs', $current_upload_file['mimetype'], $document->Document_ID, 80);
}
// delete file from temporary catalog and from cache table
//unlink($current_upload_file['filepath']);
FileCache::deleteBothFromCacheById($current_upload_file['file_id']);
if ($current_upload_file['doctype'] == self::W9) {
// if document is W9
// get additional fields
$fedId = trim($current_upload_file['fed_id']);
$newCompanyName = trim($current_upload_file['company_name']);
// get company info
$company = Companies::model()->with('client')->findByAttributes(array(
'Company_Fed_ID' => $fedId,
//.........這裏部分代碼省略.........
示例2: createThumb
/**
* Create thumbnail for image in specified size
* @param $objImage
* @param $intNewWidth
* @param $intNewHeight
* @param $intType
*/
protected function createThumb($objImage, $intNewWidth, $intNewHeight, $intType)
{
// Verify that the size doesn't already exist in the db (usually the original which
// we don't want to overwrite)
$objImageThumbnail = Images::LoadByRowidSize($objImage->id, $intType);
if (!is_null($objImageThumbnail)) {
return;
}
//Get our original file from Lightspeed
$strOriginalFile = $objImage->image_path;
$strTempThumbnail = Images::GetImageName($strOriginalFile, $intNewWidth, $intNewHeight, 'temp');
$strNewThumbnail = Images::GetImageName($strOriginalFile, $intNewWidth, $intNewHeight);
$strOriginalFileWithPath = Images::GetImagePath($strOriginalFile);
$strTempThumbnailWithPath = Images::GetImagePath($strTempThumbnail);
$strNewThumbnailWithPath = Images::GetImagePath($strNewThumbnail);
$image = Yii::app()->image->load($strOriginalFileWithPath);
$quality = _xls_get_conf('IMAGE_QUALITY', '75');
$sharpness = _xls_get_conf('IMAGE_SHARPEN', '20');
if ($sharpness != 0) {
$image->resize($intNewWidth, $intNewHeight)->quality($quality)->sharpen($sharpness);
} else {
$image->resize($intNewWidth, $intNewHeight)->quality($quality);
}
if (Images::IsWritablePath($strNewThumbnail)) {
if (_xls_get_conf('IMAGE_FORMAT', 'jpg') == 'jpg') {
$strSaveFunc = 'imagejpeg';
$strLoadFunc = "imagecreatefromjpeg";
} else {
$strSaveFunc = 'imagepng';
$strLoadFunc = "imagecreatefrompng";
}
$image->save($strNewThumbnailWithPath);
//just save normally with no special effects
//See if we have a thumbnail record in our Images table, create or update
$objThumbImage = Images::model()->findByAttributes(array('width' => $intNewWidth, 'height' => $intNewHeight, 'index' => $objImage->index, 'parent' => $objImage->id, 'product_id' => $objImage->product_id));
if (!$objThumbImage instanceof Images) {
$objThumbImage = new Images();
Images::model()->deleteAllByAttributes(array('width' => $intNewWidth, 'height' => $intNewHeight, 'parent' => $objImage->id));
//sanity check to prevent SQL UNIQUE errors
}
$objThumbImage->image_path = $strNewThumbnail;
$objThumbImage->width = $intNewWidth;
$objThumbImage->height = $intNewHeight;
$objThumbImage->parent = $objImage->id;
$objThumbImage->index = $objImage->index;
$objThumbImage->product_id = $objImage->product_id;
$objThumbImage->save();
} else {
Yii::log("Directory permissions error writing " . $strNewThumbnail, 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
}
}
示例3: actionIndex
public function actionIndex()
{
if (!empty($_POST)) {
$images = CUploadedFile::getInstancesByName('images');
if (isset($images) && count($images) > 0) {
// go through each uploaded image
foreach ($images as $image => $pic) {
$model = new Images();
$imageType = explode('.', $pic->name);
$imageType = $imageType[count($imageType) - 1];
$imageName = md5(uniqid()) . '.' . $imageType;
if ($pic->saveAs(Yii::getPathOfAlias('webroot') . '/upload/images/' . $imageName)) {
$model->image = $imageName;
$model->name = $pic->name;
$model->created = time();
$model->save();
Yii::app()->user->setFlash('success', translate('Thêm thành công.'));
}
// handle the errors here, if you want
}
}
$this->redirect(PIUrl::createUrl('/admin/images/index/'));
}
$criteria = new CDbCriteria();
$criteria->order = 'id DESC';
$count = Images::model()->count($criteria);
$pages = new CPagination($count);
// results per page
$pages->pageSize = 18;
$pages->applyLimit($criteria);
$model = Images::model()->findAll($criteria);
$this->render('index', compact('model', 'pages'));
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$file = array('image' => Input::file('image'));
// setting up rules
$rules = array('image' => 'required|mimes:jpeg,gif');
// doing the validation, passing post data, rules and the messages
$validator = Validator::make($file, $rules);
// process the login
if ($validator->fails()) {
return Redirect::to('images/create')->withErrors($validator)->withInput(Input::except('password'));
} else {
// store
// $userId = Auth::user()->id;
// $file = Input::file('image');
// $data = Img::make($file)->encode('data-url');
//
// $this->image->user_id = $userId;
// $this->image->img_name = $data->encoded;
// $this->image->save();
$file = Input::file('image');
$picture = $file->getClientOriginalName();
$generatepic = rand(32321323, 8687868678) . $picture;
$fullpath = $file->move('../public/img', $generatepic);
$images = new Images();
$images->image = $fullpath;
// $images->image = Input::file('image')->getClientOriginalName();
$images->save();
// redirect
Session::flash('message', 'Successfully uploaded!');
return Redirect::to('images');
}
}
示例5: addPost
public function addPost($user_id, $post_content, $location, $url_arr, $album, $cats)
{
$model = new Posts();
$model->post_content = $post_content;
$model->post_comment_count = 0;
$model->post_like_count = 0;
$model->post_view_count = 0;
$model->location = $location;
$model->created_at = time();
$model->status = 1;
$model->updated_at = time();
$model->user_id = $user_id;
if (!$model->save(FALSE)) {
return FALSE;
}
$cats = json_decode($cats, TRUE);
foreach ($cats as $cat) {
$cat_model = new CatPost();
$cat_model->cat_id = $cat;
$cat_model->post_id = $model->post_id;
$cat_model->status = 1;
$cat_model->created_at = time();
$cat_model->updated_at = time();
if (!$cat_model->save(FALSE)) {
return FALSE;
}
}
if (is_array($url_arr)) {
foreach ($url_arr as $url) {
$image = new Images();
$image->post_id = $model->post_id;
$image->created_at = time();
$image->created_by = $user_id;
$image->updated_at = time();
$image->status = 1;
$image->album_id = $album;
$image->image_like_count = 0;
$image->img_url = $url;
if (!$image->save(FALSE)) {
return FALSE;
}
}
} else {
$image = new Images();
$image->post_id = $model->post_id;
$image->created_at = time();
$image->created_by = $user_id;
$image->updated_at = time();
$image->status = 1;
$image->album_id = $album;
$image->image_like_count = 0;
$image->img_url = $url_arr;
if (!$image->save(FALSE)) {
return FALSE;
}
}
return $model->post_id;
}
示例6: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Images();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Images'])) {
$model->attributes = $_POST['Images'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例7: save
public function save()
{
$transaction = Yii::$app->db->beginTransaction();
try {
$characteristics = new Characteristics();
$characteristics->display_type = $this->displayType;
$characteristics->mechanism_type = $this->mechanismType;
$characteristics->starp_type = $this->starpType;
$characteristics->sex = $this->sex;
if (!$characteristics->save(false)) {
throw new \Exception('Charasteristic not save, transaction rollback');
}
$products = new Products();
$products->clk_name = $this->name;
$products->clk_description = $this->description;
$products->characteristics_id = $characteristics->id;
$products->price = $this->price;
if (!$products->save(false)) {
throw new \Exception('Product not save, transaction rollback');
}
$hashName = Yii::$app->security->generateRandomString();
$fullImagePath = self::FULL_IMAGES_PATH . $hashName . '.' . $this->images->extension;
if (!$this->images->saveAs($fullImagePath)) {
throw new \Exception('Image not save in full image path');
}
$imgSizeReduct = function ($side = 'width') use($fullImagePath) {
$size = getimagesize($fullImagePath);
if ($side === 'width') {
return $size[0] / self::THUMB_REDUCTION;
}
if ($side === 'height') {
return $size[1] / self::THUMB_REDUCTION;
}
};
$images = new Images();
$transformation = new Transformation();
$imagine = new Imagine();
$transformation->thumbnail(new Box($imgSizeReduct('width'), $imgSizeReduct('height')))->save(Yii::getAlias('@webroot/' . self::THUMBS_IMAGES_PATH . $hashName . '.' . $this->images->extension));
$transformation->apply($imagine->open(Yii::getAlias('@webroot/' . self::FULL_IMAGES_PATH . $hashName . '.' . $this->images->extension)));
$images->product_id = $products->id;
$images->img_name = $hashName . '.' . $this->images->extension;
if (!$images->save(false)) {
throw new \Exception('Images not save, transaction rollback');
}
$transaction->commit();
Yii::$app->session->addFlash('success', 'Product successfully added');
} catch (\Exception $e) {
$transaction->rollBack();
throw $e;
}
}
示例8: addImage
public static function addImage($imageOfId, $entityId, $image)
{
$destinationFileName = ImageUtils::generateFileName(basename($image));
$destinationFile = self::getImagesDirectory($entityId, $imageOfId) . $destinationFileName;
$success = Yii::app()->s3->upload($image, $destinationFile, Yii::app()->params['s3BucketName']);
if ($success) {
$images = new Images();
$images->image_of_id = $imageOfId;
$images->entity_id = $entityId;
$images->filename = $destinationFileName;
return $images->save();
} else {
return Yii::app()->s3->lastError;
}
}
示例9: add
function add($request, $response, $args)
{
$body = $request->getParsedBody();
if (!isset($_FILES['image'])) {
echo "No files uploaded!!";
return;
}
$name = $_FILES['image']['name'];
if (move_uploaded_file($_FILES['image']['tmp_name'], 'uploads/' . $name) === true) {
$url = 'uploads/' . $name;
}
$image = new Images();
$image->title = $body['title'];
$image->url = $url;
$image->save();
}
示例10: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aImages !== null) {
if ($this->aImages->isModified() || $this->aImages->isNew()) {
$affectedRows += $this->aImages->save($con);
}
$this->setImages($this->aImages);
}
if ($this->isNew()) {
$this->modifiedColumns[] = ColorPeer::ID;
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = ColorPeer::doInsert($this, $con);
$affectedRows += 1;
// we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setId($pk);
//[IMV] update autoincrement primary key
$this->setNew(false);
} else {
$affectedRows += ColorPeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
if ($this->collProductHasColors !== null) {
foreach ($this->collProductHasColors as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例11: actionUpload
public function actionUpload($id)
{
$model = $this->checkOwner($id);
Yii::import("ext.EAjaxUpload.qqFileUploader");
$allowedExtensions = param('allowedImgExtensions', array('jpg', 'jpeg', 'gif', 'png'));
//$sizeLimit = param('maxImgFileSize', 8 * 1024 * 1024);
$sizeLimit = Images::getMaxSizeLimit();
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$path = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::ORIGINAL_IMG_DIR);
$pathMod = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::MODIFIED_IMG_DIR);
$oldUMask = umask(0);
if (!is_dir($path)) {
@mkdir($path, 0777, true);
}
if (!is_dir($pathMod)) {
@mkdir($pathMod, 0777, true);
}
umask($oldUMask);
if (is_writable($path) && is_writable($pathMod)) {
touch($path . DIRECTORY_SEPARATOR . 'index.htm');
touch($pathMod . DIRECTORY_SEPARATOR . 'index.htm');
$result = $uploader->handleUpload($path . DIRECTORY_SEPARATOR, false, uniqid());
if (isset($result['success']) && $result['success']) {
$resize = new CImageHandler();
if ($resize->load($path . DIRECTORY_SEPARATOR . $result['filename'])) {
$resize->thumb(param('maxImageWidth', 1024), param('maxImageHeight', 768), Images::KEEP_PHOTO_PROPORTIONAL)->save();
$image = new Images();
$image->id_object = $model->id;
$image->id_owner = $model->owner_id;
$image->file_name = $result['filename'];
$image->save();
} else {
$result['error'] = 'Wrong image type.';
@unlink($path . DIRECTORY_SEPARATOR . $result['filename']);
}
}
} else {
$result['error'] = 'Access denied.';
}
// to pass data through iframe you will need to encode all html tags
$result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
echo $result;
}
示例12: actionIndex
public function actionIndex()
{
if (!empty($_POST)) {
$images = CUploadedFile::getInstancesByName('images');
if (isset($images) && count($images) > 0) {
// go through each uploaded image
foreach ($images as $image => $pic) {
$model = new Images();
$model->scenario = 'image';
$imageName = $this->getFileName($pic);
$model->image = $imageName;
if ($pic->saveAs(Yii::getPathOfAlias('webroot') . '/upload/images/' . $imageName)) {
$model->link = $imageName;
$model->name = $pic->name;
$model->created = time();
$model->album_id = Images::$IMAGE_PHOTO;
//dump($model);
if ($model->save()) {
Yii::app()->user->setFlash('success', translate('Thêm thành công.'));
} else {
dump($model->errors);
}
}
// handle the errors here, if you want
}
}
$this->redirect(PIUrl::createUrl('admin/images/index'));
}
$criteria = new CDbCriteria();
$criteria->condition = 'album_id=:album_id';
$criteria->order = 'id DESC';
$criteria->params = array(':album_id' => Images::$IMAGE_PHOTO);
$count = Images::model()->count($criteria);
$pages = new CPagination($count);
// results per page
$pages->pageSize = 18;
$pages->applyLimit($criteria);
$listImage = Images::model()->findAll($criteria);
//dump($model);
$dataAlbums = Albums::model()->getAlbums();
$this->render('index', compact('pages', 'dataAlbums', 'listImage'));
}
示例13: actionCreate
public function actionCreate()
{
$model = new DatasetAttributes();
$att = Attribute::model()->findByAttributes(array('attribute_name' => Attribute::FUP));
if (!$att) {
$att = new Attribute();
$att->attribute_name = Attribute::FUP;
$att->definition = '';
$att->save();
}
$model->attribute_id = $att->id;
$image = new Images();
if (isset($_POST['DatasetAttributes'])) {
$args = $_POST['DatasetAttributes'];
$exist = DatasetAttributes::model()->findByAttributes(array('dataset_id' => $args['dataset_id'], 'attribute_id' => $att->id));
if ($exist) {
$model = $exist;
}
$model->attributes = $args;
$model->value = '';
//$image->attributes = $_POST['Images'];
$image->license = "no license";
$image->photographer = "no author";
$image->source = "gigadb";
if ($image->validate()) {
$image->save();
} else {
Yii::log(print_r($image->getErrors(), true), 'debug');
}
if ($image) {
$model->image_id = $image->id;
}
if ($model->validate()) {
$model->save();
$this->redirect('/dataset/' . $model->dataset->identifier);
} else {
Yii::log(print_r($model->getErrors(), true), 'debug');
}
}
$this->render('create', array('model' => $model, 'image' => $image));
}
示例14: actionInsert
public function actionInsert()
{
if (isset($_POST['choose'])) {
$post = new Posts();
$post->status = 0;
$post->updated_at = time();
$post->created_at = time();
$post->user_id = 1;
$post->post_content = $_POST['caption'];
$post->save(FALSE);
$image = new Images();
$image->created_at = time();
$image->updated_at = time();
$image->post_id = $post->post_id;
$image->created_by = 1;
$image->img_url = $_POST['image_standard_url'];
$image->status = 0;
$image->save(FALSE);
}
echo CJSON::encode(array('message' => 'success'));
}
示例15: uploadImages
public function uploadImages()
{
if ($this->validate()) {
$transformation = new Transformation();
$imagine = new Imagine();
//$randHeight = function() {
//return rand(250, 330);
//};
foreach ($this->imageFiles as $file) {
/* @var $file \yii\web\UploadedFile */
$imageRandName = Yii::$app->security->generateRandomString(12);
$fullImagePath = self::FULL_IMAGES_PATH . $imageRandName . '.' . $file->extension;
$file->saveAs($fullImagePath);
$imgSizeReduct = function ($side = 'width') use($fullImagePath) {
$size = getimagesize($fullImagePath);
if ($side === 'width') {
return $size[0] / self::THUMB_REDUCTION;
}
if ($side === 'height') {
return $size[1] / self::THUMB_REDUCTION;
}
};
$transformation->thumbnail(new Box($imgSizeReduct(), $imgSizeReduct('height')))->save(Yii::getAlias('@webroot/' . self::THUMBS_IMAGES_PATH . $imageRandName . '.' . $file->extension));
$transformation->apply($imagine->open(Yii::getAlias('@webroot/' . self::FULL_IMAGES_PATH . $imageRandName . '.' . $file->extension)));
$images = new Images();
$images->name = $imageRandName . '.' . $file->extension;
$images->alt = $this->alt;
if (!$images->save()) {
Yii::$app->session->addFlash('danger', 'Image not saved into data base!');
return false;
}
}
Yii::$app->session->addFlash('success', 'Image uploaded successfully');
return true;
}
Yii::$app->session->addFlash('danger', 'Incorrect data');
return false;
}