本文整理匯總了PHP中Images::getFileNameParts方法的典型用法代碼示例。如果您正苦於以下問題:PHP Images::getFileNameParts方法的具體用法?PHP Images::getFileNameParts怎麽用?PHP Images::getFileNameParts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Images
的用法示例。
在下文中一共展示了Images::getFileNameParts方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: image_url
/**
* $image : string
*/
function image_url($image, $type = null, $force_no_base = false, $use_temp = false, $new_ext = null)
{
if (!is_null($type)) {
$images_types = sfConfig::get('app_images_types');
$suffix = $images_types[$type]['suffix'];
} else {
$suffix = '';
}
list($image_name, $image_ext) = Images::getFileNameParts($image);
$base_path = $force_no_base ? '' : sfConfig::get('app_static_url');
$base_path .= DIRECTORY_SEPARATOR . sfConfig::get('app_upload_dir') . DIRECTORY_SEPARATOR . ($use_temp ? sfConfig::get('app_images_temp_directory_name') : sfConfig::get('app_images_directory_name')) . DIRECTORY_SEPARATOR;
return $base_path . $image_name . $suffix . (isset($new_ext) ? $new_ext : $image_ext);
}
示例2: 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);
}