本文整理匯總了PHP中Images::post方法的典型用法代碼示例。如果您正苦於以下問題:PHP Images::post方法的具體用法?PHP Images::post怎麽用?PHP Images::post使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Images
的用法示例。
在下文中一共展示了Images::post方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: upload_to
/**
* upload a file as a image attach to a given anchor
* to be used in custom "edit_as" script
*
* @global string $context
* @param object $anchor
* @param array $file (from $_FILES)
* @param bool $set_as_thumb
* @param bool $put
*/
public static function upload_to($anchor, $file, $set_as_thumb = false, $put = false)
{
global $context;
// attach some image
$path = Files::get_path($anchor->get_reference(), 'images');
// $_REQUEST['action'] = 'set_as_icon'; // instruction for image::upload
if (isset($file) && ($uploaded = Files::upload($file, $path, array('Image', 'upload')))) {
// prepare image informations
$image = array();
$image['image_name'] = $uploaded;
$image['image_size'] = $file['size'];
$image['thumbnail_name'] = 'thumbs/' . $uploaded;
$image['anchor'] = $anchor->get_reference();
//$combined = array_merge($image, $_FILES);
// post the image which was uploaded
if ($image['id'] = Images::post($image)) {
// successfull post
$context['text'] .= '<p>' . i18n::s('Following image has been added:') . '</p>' . Codes::render_object('image', $image['id']) . '<br style="clear:left;" />' . "\n";
// set image as icon and thumbnail
if ($set_as_thumb) {
// delete former icon if any
/*if(isset($anchor->item['icon_url'])
&& $anchor->item['icon_url']
&& $match = Images::get_by_anchor_and_name($anchor->get_reference(), pathinfo($anchor->item['icon_url'],PATHINFO_BASENAME))) {
if($match['id'] != $image['id'])
Images::delete($match['id']);
}*/
$fields = array('thumbnail_url' => Images::get_thumbnail_href($image), 'icon_url' => Images::get_icon_href($image));
if ($put) {
$fields['id'] = $_REQUEST['id'];
$class = $anchor->get_static_group_class();
$class::put_attributes($fields);
} else {
$_REQUEST = array_merge($_REQUEST, $fields);
}
}
}
}
}
示例2: submit_image
//.........這裏部分代碼省略.........
return NULL;
}
// file size
$file_size = strlen($content);
// sanity check
if ($file_size < 7) {
Logger::remember('agents/messages.php: Short image skipped', $file_name);
return NULL;
}
// sanity check
if (!$anchor) {
Logger::remember('agents/messages.php: No anchor to use for submitted image', $file_name);
return NULL;
}
// get anchor data -- this is a mutable object
$host = Anchors::get($anchor, TRUE);
if (!is_object($host)) {
Logger::remember('agents/messages.php: Unknown anchor ' . $anchor, $file_name);
return NULL;
}
// create target folders
$file_path = Files::get_path($anchor, 'images');
if (!Safe::make_path($file_path)) {
Logger::remember('agents/messages.php: Impossible to create ' . $file_path);
return NULL;
}
if (!Safe::make_path($file_path . '/thumbs')) {
Logger::remember('agents/messages.php: Impossible to create ' . $file_path . '/thumbs');
return NULL;
}
$file_path = $context['path_to_root'] . $file_path . '/';
// save the entity in the file system
if (!($file = Safe::fopen($file_path . $file_name, 'wb'))) {
Logger::remember('agents/messages.php: Impossible to open ' . $file_path . $file_name);
return NULL;
}
if (fwrite($file, $content) === FALSE) {
Logger::remember('agents/messages.php: Impossible to write to ' . $file_path . $file_name);
return NULL;
}
fclose($file);
// get image information
if (!($image_information = Safe::GetImageSize($file_path . $file_name))) {
Safe::unlink($file_path . $file_name);
Logger::remember('agents/messages.php: No image information in ' . $file_path . $file_name);
return NULL;
}
// we accept only gif, jpeg and png
if ($image_information[2] != 1 && $image_information[2] != 2 && $image_information[2] != 3) {
Safe::unlink($file_path . $file_name);
Logger::remember('agents/messages.php: Rejected image type for ' . $file_path . $file_name);
return NULL;
}
// build a thumbnail
$thumbnail_name = 'thumbs/' . $file_name;
// do not stop on error
include_once $context['path_to_root'] . 'images/image.php';
if (!Image::shrink($file_path . $file_name, $file_path . $thumbnail_name, FALSE, FALSE)) {
Logger::remember('agents/messages.php: No thumbnail has been created for ' . $file_path . $file_name);
}
// resize the image where applicable
if (Image::adjust($file_path . $file_name, FALSE)) {
$file_size = Safe::filesize($file_path . $file_name);
}
// all details
$details = array();
// image size
if ($image_information = Safe::GetImageSize($file_path . $file_name)) {
$details[] = i18n::c('Size') . ': ' . $image_information[0] . ' x ' . $image_information[1];
}
// update image description
$item = array();
$item['anchor'] = $anchor;
$item['image_name'] = $file_name;
$item['thumbnail_name'] = $thumbnail_name;
$item['image_size'] = $file_size;
$item['description'] = '';
if (isset($content_description) && $content_description != $file_name) {
$item['description'] .= $content_description;
}
if (@count($details)) {
$item['description'] .= "\n\n" . '<p class="details">' . implode("<br />\n", $details) . "</p>\n";
}
$item['edit_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', time());
$item['edit_name'] = $user['nick_name'];
$item['edit_id'] = $user['id'];
$item['edit_address'] = $user['email'];
// create an image record in the database
include_once $context['path_to_root'] . 'images/images.php';
if (!($item['id'] = Images::post($item))) {
Logger::remember('agents/messages.php: Impossible to save image ' . $item['image_name']);
return NULL;
}
if ($context['debug_messages'] == 'Y') {
Logger::remember('agents/messages.php: Messages::submit_image()', $item, 'debug');
}
// insert the image in the anchor page
$host->touch('image:create', $item['id'], TRUE);
return 'image:' . $item['id'];
}
示例3: array
// an image has been found
if (Image::upload($node, $context['path_to_root'] . $file_path . '/', TRUE)) {
$count++;
// resize the image where applicable
Image::adjust($context['path_to_root'] . $file_path . '/' . $node, TRUE, 'standard');
// if the file does not exist yet
if (!($item =& Images::get_by_anchor_and_name($anchor->get_reference(), $node))) {
// create a new image record for this file
$item = array();
$item['anchor'] = $anchor->get_reference();
$item['image_name'] = $node;
$item['thumbnail_name'] = 'thumbs/' . $node;
$item['image_size'] = Safe::filesize($file_path . '/' . $node);
$item['use_thumbnail'] = 'A';
// ensure it is always displayed as a clickable small image
$item['id'] = Images::post($item);
}
// ensure that the image is in anchor description field
$nodes[$node] = $item['id'];
}
}
Safe::closedir($handle);
// embed uploaded images in alphabetical order
ksort($nodes);
foreach ($nodes as $name => $id) {
$anchor->touch('image:create', $id);
}
}
// clear floating thumbnails
if ($count) {
$anchor->touch('clear');