当前位置: 首页>>代码示例>>PHP>>正文


PHP Images::moveAll方法代码示例

本文整理汇总了PHP中Images::moveAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Images::moveAll方法的具体用法?PHP Images::moveAll怎么用?PHP Images::moveAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Images的用法示例。


在下文中一共展示了Images::moveAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: customSave

 public static function customSave($name, $filename, $associated_doc_id, $user_id, $model, $activities = array(), $categories = array(), $image_type = 1)
 {
     $base_path = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR;
     $from = $base_path . sfConfig::get('app_images_temp_directory_name');
     $to = $base_path . sfConfig::get('app_images_directory_name');
     c2cTools::log("linking image {$filename} to {$model} {$associated_doc_id}, with title \"{$name}\", user {$user_id} ");
     // save a new image...
     $image = new Image();
     $image->setCulture(sfContext::getInstance()->getUser()->getCulture());
     $image->set('name', $name);
     $image->set('filename', $filename);
     // get and store image dimensions and size
     $size = getimagesize($from . DIRECTORY_SEPARATOR . $filename);
     if ($size) {
         $image->set('width', $size[0]);
         $image->set('height', $size[1]);
     }
     $image->set('file_size', filesize($from . DIRECTORY_SEPARATOR . $filename));
     // here, read eventual lon, lat, elevation and other interesting fields from exif tag...
     // (nb: always after $image->set('filename', $filename))
     $image->populateWithExifDataFrom($from . DIRECTORY_SEPARATOR . $filename);
     // here, copy activities field from the linked document (if it exists):
     if (!empty($activities)) {
         $image->set('activities', $activities);
     }
     if (!empty($categories)) {
         $image->set('categories', $categories);
     }
     $image->set('image_type', $image_type);
     $image->set('has_svg', Images::hasSVG($filename, $from));
     // then save:
     $image->doSaveWithMetadata($user_id, false, 'Image uploaded');
     c2cTools::log('associating and moving files');
     $image_id = $image->get('id');
     $type = c2cTools::Model2Letter($model) . 'i';
     // associate it
     $a = new Association();
     $a->doSaveWithValues($associated_doc_id, $image_id, $type, $user_id);
     // move to uploaded images directory (move the big, small and all other configured in yaml)
     Images::moveAll($filename, $from, $to);
     return $image_id;
 }
开发者ID:snouhaud,项目名称:camptocamp.org,代码行数:42,代码来源:Image.class.php

示例2: executeEdit

 /**
  * Executes edit action.
  */
 public function executeEdit()
 {
     // populate objects for form display depending on what we are doing (creating, editing)
     $this->setEditFormInformation();
     // All modules will use the same template
     $this->setTemplate('../../documents/templates/edit');
     $document = $this->document;
     $module_name = $this->getModuleName();
     $this->document_name = $document->get('name');
     // Culture (lang) is automatically defined in Hydrate,
     // redefined in the model.
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         $lang = $this->getRequestParameter('lang');
         $user_id = $this->getUser()->getId();
         $is_minor = $this->getRequestParameter('rev_is_minor', false);
         $message = $this->getRequestParameter('rev_comment');
         $document->setCulture($lang);
         $old_lon = $document->get('lon');
         $old_lat = $document->get('lat');
         $this->setDataFields($document);
         // upload potential GPX file to server and set WKT field
         // or upload a new version of an image
         $request = $this->getRequest();
         if ($request->hasFiles()) {
             c2cTools::log('request has files');
             if ($request->getFileName('image_new_version') && $module_name == 'images') {
                 c2cTools::log('new image uploaded');
                 $base_path = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR;
                 $temp_dir = $base_path . sfConfig::get('app_images_temp_directory_name');
                 $upload_dir = $base_path . sfConfig::get('app_images_directory_name');
                 $filename = $request->getFiles();
                 $unique_filename = c2cTools::generateUniqueName();
                 $file_ext = Images::detectExtension($filename['image_new_version']['tmp_name']);
                 // upload file in a temporary folder
                 $new_location = $temp_dir . DIRECTORY_SEPARATOR . $unique_filename . $file_ext;
                 sfLoader::loadHelpers(array('General'));
                 $redir_route = '@document_by_id_lang_slug?module=' . $module_name . '&id=' . $this->document->get('id') . '&lang=' . $this->document->getCulture() . '&slug=' . get_slug($this->document);
                 if (!$request->moveFile('image_new_version', $new_location)) {
                     return $this->setErrorAndRedirect('Failed moving uploaded file', $redir_route);
                 }
                 if ($file_ext == '.svg') {
                     if (!SVG::rasterize($temp_dir . DIRECTORY_SEPARATOR, $unique_filename, $file_ext)) {
                         return $this->setErrorAndRedirect('Failed rasterizing svg file', $redir_route);
                     }
                     $document->set('has_svg', true);
                 } else {
                     $document->set('has_svg', false);
                 }
                 // generate thumbnails (ie. resized images: "BI"/"SI")
                 Images::generateThumbnails($unique_filename, $file_ext, $temp_dir);
                 // move to uploaded images directory
                 if (!Images::moveAll($unique_filename . $file_ext, $temp_dir, $upload_dir)) {
                     return $this->setErrorAndRedirect('image dir unavailable', $redir_route);
                 }
                 // update filename and image properties
                 $document->set('filename', $unique_filename . $file_ext);
                 $size = getimagesize($upload_dir . DIRECTORY_SEPARATOR . $unique_filename . $file_ext);
                 if ($size) {
                     $document->set('width', $size[0]);
                     $document->set('height', $size[1]);
                 }
                 $document->set('file_size', filesize($upload_dir . DIRECTORY_SEPARATOR . $unique_filename . $file_ext));
                 // populate with new exif data, if any...
                 $document->populateWithExifDataFrom($upload_dir . DIRECTORY_SEPARATOR . $unique_filename . $file_ext);
             }
             if ($request->getFileName('gps_data') && in_array($module_name, array('routes', 'outings'))) {
                 // it is necessary to preserve both tests nested.
                 if ($wkt = $this->getWktFromFileUpload($request)) {
                     c2cTools::log('wkt extracted');
                     $document->set('geom_wkt', $wkt);
                     // NB: these fields exist in both objects for which a file upload is possible (outings, routes)
                     $_a = ParseGeo::getCumulatedHeightDiffFromWkt($wkt);
                     if (!$document->get('height_diff_up')) {
                         $document->set('height_diff_up', $_a['up']);
                         c2cTools::log('height diff up set from wkt : ' . $_a['up']);
                     }
                     if (!$document->get('height_diff_down')) {
                         $document->set('height_diff_down', $_a['down']);
                         c2cTools::log('height diff down set from wkt : ' . $_a['down']);
                     }
                     $message = '[geodata] ' . (!$message ? "Edit with geometry upload" : $message);
                 } else {
                     $this->getRequest()->setError('gps_data', 'invalid gpx file');
                     return false;
                 }
             }
         }
         if (count($this->document->getModified()) == 0 && count($this->document->getCurrentI18nObject()->getModified()) == 0) {
             // no change of the document was detected
             // => redirects to the document without saving anything
             $this->redirectToView();
             return;
         }
         // we prevent here concurrent edition :
         // fake data so that second test always fails on summit creation (and when document is an archive) :
         $rev_when_edition_begun = 1;
         $current_rev = 0;
//.........这里部分代码省略.........
开发者ID:snouhaud,项目名称:camptocamp.org,代码行数:101,代码来源:actions.class.php

示例3: executeRotate

 public function executeRotate()
 {
     $id = $this->getRequestParameter('id');
     $referer = $this->getRequest()->getReferer();
     $degrees = (int) $this->getRequestParameter('degrees');
     if ($degrees !== 90 && $degrees !== -90) {
         $referer = $this->getRequest()->getReferer();
         $this->setErrorAndRedirect('Bad rotation value', $referer);
     }
     $doc = Document::find('Image', $id);
     $this->document = $doc;
     if (!$doc) {
         $this->setErrorAndRedirect('Image not found', $referer);
     }
     // check if the user has the right for editing the image
     $this->filterAuthorizedPeople($id);
     $temp_dir = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_images_temp_directory_name') . DIRECTORY_SEPARATOR;
     $upload_dir = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_images_directory_name') . DIRECTORY_SEPARATOR;
     list($filename, $extension) = Images::getFileNameParts($doc->getFilename());
     $unique_filename = c2cTools::generateUniqueName();
     // because images on production get migrated after a while on a different server
     // we need to check if the file exists on disk before trying to rotate the image
     if (!file_exists($upload_dir . $filename . $extension)) {
         $this->setErrorAndRedirect('Image cannot be rotated anymore', $referer);
     }
     Images::rotateImage($upload_dir . $filename . $extension, $temp_dir . $unique_filename . $extension, $degrees);
     Images::generateThumbnails($unique_filename, $extension, $temp_dir);
     if (!Images::moveAll($unique_filename . $extension, $temp_dir, $upload_dir)) {
         $this->setErrorAndRedirect('Rotation failed', $referer);
     }
     // we don't create a new image document version, instead we directly
     // update the filename field and clear cache
     // We need to change it everytime it appears, since we could have several image versions
     // with same filename (if non-i18n data like categroies has been changed)
     try {
         $conn = sfDoctrine::Connection();
         $conn->beginTransaction();
         Doctrine_Query::create()->update('ImageArchive ia')->set('ia.filename', '?')->where('ia.id = ? AND ia.filename = ?', array($unique_filename . $extension, $id, $filename . $extension))->execute();
         $conn->commit();
         // Delete old files
         Images::removeAll($filename . $extension, $upload_dir);
     } catch (Exception $e) {
         $conn->rollback();
         // delete rotated images
         Images::removeAll($unique_filename . $extension, $upload_dir);
         $this->setErrorAndRedirect('Rotation failed', $referer);
     }
     // clear cache of current doc
     $this->clearCache('images', $id);
     // clear views of the associated docs in every language (content+interface):
     $associated_docs = Association::findAllAssociatedDocs($id, array('id', 'module'));
     foreach ($associated_docs as $doc) {
         // clear their view cache
         $this->clearCache($doc['module'], $doc['id'], false, 'view');
     }
     // redirect to view
     $this->setNoticeAndRedirect('Image rotated successfully', $referer);
 }
开发者ID:snouhaud,项目名称:camptocamp.org,代码行数:58,代码来源:actions.class.php


注:本文中的Images::moveAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。