本文整理汇总了PHP中Files::fitSquare方法的典型用法代码示例。如果您正苦于以下问题:PHP Files::fitSquare方法的具体用法?PHP Files::fitSquare怎么用?PHP Files::fitSquare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Files
的用法示例。
在下文中一共展示了Files::fitSquare方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadimageAction
public function uploadimageAction()
{
// Where we come from
$source = $this->_getParam('source');
// Verify that it is authorized
if (!in_array($source, array('design', 'profile'))) {
throw new Stuffpress_Exception("Invalid source specified {$source}");
}
// What are we uploading
$image = $this->_getParam('image');
$property = "{$image}_image";
// Was a file uploaded ?
if (!isset($_FILES['file'])) {
$this->addErrorMessage('Upload failed: no files received on server end.');
return $this->_forward('index', $source, 'admin');
}
// Validate the uploaded file
$tmp_file = $_FILES['file']['tmp_name'];
$file_name = basename($_FILES['file']['name']);
$file_type = $_FILES['file']['type'];
$file_ext = substr(trim(substr($file_name, strrpos($file_name, '.')), '.'), 0, 4);
// returns the ext only
// Check file size
if ($_SERVER['CONTENT_LENGTH'] > 2000000) {
$this->addErrorMessage('Upload failed: your file size is above 2Mbytes.');
return $this->_forward('index', $source, 'admin');
}
// Check file extension
if (!in_array(strtolower($file_ext), array("gif", "jpg", "png", "jpeg"))) {
$this->addErrorMessage('Upload failed: we only support jpg, gif and png files.');
return $this->_forward('index', $source, 'admin');
}
// Assign a random name to the file
$key = Stuffpress_Token::create(32);
$root = Zend_Registry::get("root");
$uploaddir = $root . "/upload/";
$uploadfile = $uploaddir . '/' . $key;
// Move the file to the upload folder
if (!move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
$this->addErrorMessage('Upload failed: your file size is above 2Mbytes.');
return $this->_forward('index', $source, 'admin');
}
// Store the file in the database
$files = new Files(array(Stuffpress_Db_Table::USER => $this->_application->user->id));
$file_id = $files->addFile($key, $file_name, "Lifestream custom image", $file_type, $file_ext);
// Build a thumbnail of the file
try {
$files->fitSquare($file_id, 75, 'thumbnails');
} catch (Exception $e) {
$message = $e->getMessage();
$this->addErrorMessage("Upload failed: could not process image ({$message})");
$files->deleteFile($key);
return $this->_forward('index', $source, 'admin');
}
// Replace the user property with the new file and delete the older one
$properties = new Properties(array(Properties::KEY => $this->_application->user->id));
$old_file = $properties->getProperty($property);
$properties->setProperty($property, $key);
if ($old_file) {
$files->deleteFile($old_file);
}
// If we are here, everything went smooth
$this->addStatusMessage('Your file was successfully uploaded');
return $this->_forward('index', $source, 'admin');
}
示例2: execute
public function execute()
{
// get a logger
$logger = Zend_Registry::get("logger");
echo "Memory usage on startup: " . memory_get_usage() . "\r\n";
// Access the email
$mail = new Zend_Mail_Storage_Pop3(array('host' => 'xxxxxx', 'user' => 'xxxxxx', 'password' => 'xxxxxx', 'ssl' => 'SSL'));
// If no new email, goodbye
if ($mail->countMessages() == 0) {
$log = "No new emails to process.";
echo "{$log}\r\n";
$logger->log($log, Zend_Log::INFO);
exit;
}
$email_count = 0;
foreach ($mail as $messageNum => $message) {
// A bit of feedback
$log = "Message to {$message->to}.. (mem: " . memory_get_usage() . ")...";
echo "{$log}";
$logger->log($log, Zend_Log::INFO);
// Get the user, if not we continue
if (!($user = $this->getUser($message->to))) {
$log = "skipped.";
echo "{$log}\r\n";
$logger->log($log, Zend_Log::INFO);
$mail->removeMessage($messageNum);
continue;
}
// Assign the shard value
Zend_Registry::set("shard", $user['id']);
$this->_user = $user;
$this->_properties = new Properties(array(Stuffpress_Db_Properties::KEY => $user['id']));
// Get the subject
try {
$subject = $this->mimeWordDecode(trim($message->subject));
} catch (Exception $e) {
$subject = "";
}
// Get the content
$foundPart = null;
$plain_text = "";
$html_text = "";
$latitude = false;
$longitude = false;
$image = false;
$audio = false;
$files = new Files();
$timestamp = time();
foreach (new RecursiveIteratorIterator($message) as $part) {
try {
$part_type = strtok($part->contentType, ';');
if ($part_type == 'text/plain') {
$charset = $this->getCharset($part->contentType);
$plain_text = $this->recode(trim($part->getContent()), $charset);
} else {
if ($part_type == 'text/html') {
$charset = $this->getCharset($part->contentType);
$html_text = $this->recode(trim($part->getContent()), $charset);
} else {
if (substr_compare($part_type, 'image', 0, 5) == 0) {
if ($details = $this->getFileDetails($part->contentType)) {
if ($content = base64_decode($part->getContent())) {
$file_id = $files->saveFile($content, $details['name'], $details['mime'], "Email upload");
$file = $files->getFile($file_id);
$key = $file->key;
$files->fitWidth($file_id, 240, 'small');
$files->fitWidth($file_id, 500, 'medium');
$files->fitWidth($file_id, 1024, 'large');
$files->fitSquare($file_id, 75, 'thumbnails');
$exif = $files->readExif($file_id);
// Retrieve the picture date/time
if (isset($exif['DateTimeOriginal'])) {
$timestamp = Stuffpress_Date::strToTimezone($exif['DateTimeOriginal'], $this->_properties->getProperty('timezone'));
}
// Get longitude if provided
if (!empty($exif['GPSLongitude']) && count($exif['GPSLongitude']) == 3 && !empty($exif['GPSLongitudeRef'])) {
$longitude = ($exif['GPSLongitudeRef'] == 'W' ? '-' : '') . Stuffpress_Exif::exif_gpsconvert($exif['GPSLongitude']);
}
// Get latitude
if (!empty($exif['GPSLatitude']) && count($exif['GPSLatitude']) == 3 && !empty($exif['GPSLatitudeRef'])) {
$latitude = ($exif['GPSLatitudeRef'] == 'S' ? '-' : '') . Stuffpress_Exif::exif_gpsconvert($exif['GPSLatitude']);
}
$image = $key;
}
}
} else {
if (substr_compare($part_type, 'audio', 0, 5) == 0) {
if ($details = $this->getFileDetails($part->contentType)) {
if ($content = base64_decode($part->getContent())) {
$file_id = $files->saveFile($content, $details['name'], $details['mime'], "Email upload");
$file = $files->getFile($file_id);
$audio = $file->key;
}
}
}
}
}
}
} catch (Zend_Mail_Exception $e) {
// ignore
//.........这里部分代码省略.........
示例3: newItem
private function newItem($values) {
// Local variables
$files = new Files();
// If an image and the URL was given, we download the image and store it
if ((@$values['type'] == 'image') && ($url = @$values['url']) && (strlen($url) > 0)) {
$file_id = $files->downloadFile($url, "download");
$file = $files->getFile($file_id);
$key = $file->key;
}
// If a file was uploaded, we process it
else if (@$_FILES['file']['tmp_name']) {
try {
$file_id = $files->processFile($values['file'], $_FILES['file'], 'Posted file');
$file = $files->getFile($file_id);
$key = $file->key;
}
catch(Exception $e) {
$this->addErrorMessage("Unknown error occured");
return $this->_forward(@$values['type']);
}
}
// If an image and file available, resize
if ((@$values['type'] == 'image') && ($file_id > 0)) {
$files->fitWidth($file_id, 240, 'small');
$files->fitWidth($file_id, 500, 'medium');
$files->fitWidth($file_id, 1024, 'large');
$files->fitSquare($file_id, 75, 'thumbnails');
$exif = $files->readExif($file_id);
}
// Process the date if available
$date_type = @$values['date_type'];
if ($date_type == 'other') {
$timestamp = Stuffpress_Date::strToTimezone($values['date'], $this->_properties->getProperty('timezone'));
}
else if ($date_type == 'taken' && $exif) {
if (isset($exif['DateTimeOriginal'])) {
$timestamp = Stuffpress_Date::strToTimezone($exif['DateTimeOriginal'], $this->_properties->getProperty('timezone'));
} else {
$timestamp = time();
}
}
else {
$timestamp = time();
}
// Process the tags if available
$tags = @explode(',', $values['tags']);
// Prepare the values for the database
$data = array();
$data['published'] = @$timestamp;
$data['type'] = @$values['type'];
$data['file'] = @$key;
$data['url'] = @$values['url'];
$data['title'] = @$values['title'];
$data['link'] = @$values['link'];
$data['embed'] = @$values['embed'];
$data['text'] = @$values['text'];
// Add or update the item
$source = StuffpressModel::forUser($this->_application->user->id);
$data_table = new Data();
$item_id = $source->addItem($data, $data['published'], $data['type'], $tags, false, false, $data['title']);
$source_id = $source->getID();
// fetch the new item
$item = $data_table->getItem($source_id, $item_id);
// Get longitude if provided
if (!empty($exif['GPSLongitude']) && count($exif['GPSLongitude']) == 3 && !empty($exif['GPSLongitudeRef'])) {
$longitude = ($exif['GPSLongitudeRef']== 'W' ? '-' : '') . Stuffpress_Exif::exif_gpsconvert( $exif['GPSLongitude'] );
} else {
$longitude = @$values['longitude'];
}
// Get latitude
if (!empty($exif['GPSLatitude']) && count($exif['GPSLatitude']) == 3 && !empty($exif['GPSLatitudeRef'])) {
$latitude = ($exif['GPSLatitudeRef']== 'S' ? '-' : '') . Stuffpress_Exif::exif_gpsconvert( $exif['GPSLatitude'] );
} else {
$latitude = @$values['latitude'];
}
// Set it
if ($latitude && $longitude) {
$data_table->setLocation($source_id, $item_id, $latitude, $longitude, 0);
}
// Send notification if twitter post is enabled
if ($this->_properties->getProperty('twitter_auth') && $values['twitter_notify']) {
$this->notifyTwitter($item);
}
// Ping blog search engines
$this->ping();
// Redirect to the timeline
//.........这里部分代码省略.........
示例4: setKeyImage
private function setKeyImage($story_id, $url)
{
$stories = new Stories();
$files = new Files();
$file_id = $files->downloadFile($url, "");
$files->fitSquare($file_id, 50, 'thumbnails');
$file = $files->getFile($file_id);
$stories->setThumbnail($story_id, $file->key);
}