本文整理汇总了PHP中FD::uploader方法的典型用法代码示例。如果您正苦于以下问题:PHP FD::uploader方法的具体用法?PHP FD::uploader怎么用?PHP FD::uploader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FD
的用法示例。
在下文中一共展示了FD::uploader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadPhoto
public function uploadPhoto($log_usr = 0, $type = null)
{
// Get current logged in user.
$my = FD::user($log_usr);
// Get user access
$access = FD::access($my->id, SOCIAL_TYPE_USER);
// Load up the photo library
$lib = FD::photo($log_usr, $type);
// Define uploader options
$options = array('name' => 'file', 'maxsize' => $lib->getUploadFileSizeLimit());
// Get uploaded file
$file = FD::uploader($options)->getFile();
// Load the iamge object
$image = FD::image();
$image->load($file['tmp_name'], $file['name']);
// Detect if this is a really valid image file.
if (!$image->isValid()) {
return "invalid image";
}
// Load up the album's model.
$albumsModel = FD::model('Albums');
// Create the default album if necessary
$album = $albumsModel->getDefaultAlbum($log_usr, $type, SOCIAL_ALBUM_STORY_ALBUM);
// Bind photo data
$photo = FD::table('Photo');
$photo->uid = $log_usr;
$photo->type = $type;
$photo->user_id = $my->id;
$photo->album_id = $album->id;
$photo->title = $file['name'];
$photo->caption = '';
$photo->state = 1;
$photo->ordering = 0;
// Set the creation date alias
$photo->assigned_date = FD::date()->toMySQL();
// Trigger rules that should occur before a photo is stored
$photo->beforeStore($file, $image);
// Try to store the photo.
$state = $photo->store();
// Load the photos model
$photosModel = FD::model('Photos');
// Get the storage path for this photo
$storage = FD::call('Photos', 'getStoragePath', array($album->id, $photo->id));
// Get the photos library
$photoLib = FD::get('Photos', $image);
$paths = $photoLib->create($storage);
// Create metadata about the photos
if ($paths) {
foreach ($paths as $type => $fileName) {
$meta = FD::table('PhotoMeta');
$meta->photo_id = $photo->id;
$meta->group = SOCIAL_PHOTOS_META_PATH;
$meta->property = $type;
$meta->value = $storage . '/' . $fileName;
$meta->store();
// We need to store the photos dimension here
list($width, $height, $imageType, $attr) = getimagesize(JPATH_ROOT . $storage . '/' . $fileName);
// Set the photo dimensions
$meta = FD::table('PhotoMeta');
$meta->photo_id = $photo->id;
$meta->group = SOCIAL_PHOTOS_META_WIDTH;
$meta->property = $type;
$meta->value = $width;
$meta->store();
$meta = FD::table('PhotoMeta');
$meta->photo_id = $photo->id;
$meta->group = SOCIAL_PHOTOS_META_HEIGHT;
$meta->property = $type;
$meta->value = $height;
$meta->store();
}
}
// After storing the photo, trigger rules that should occur after a photo is stored
//$photo->afterStore( $file , $image );
//$sphoto = new SocialPhotos($photo_obj->id);
return $photo;
}
示例2: addFile
/**
* Allows caller to upload files
*
* @since 1.2
* @access public
* @param string
* @return
*/
public function addFile($title = null)
{
if (!$this->hasWriteAccess()) {
return FD::exception(JText::_('COM_EASYSOCIAL_EXPLORER_NO_ACCESS_TO_UPLOAD'));
}
// Ensure that the storage path really exists on the site
FD::makeFolder($this->storagePath);
// Get the maximum size allowed from the child
$max = $this->getMaxSize();
// Define uploader options
$options = array('name' => 'file', 'maxsize' => $max);
// Get uploaded file from $_FILE
$file = FD::uploader($options)->getFile();
// If there was an error getting uploaded file, stop.
if ($file instanceof SocialException) {
return $file;
}
// Get filename
$name = $file['name'];
// Get the folder to store this item to.
$collectionId = JRequest::getInt('id', 0);
$table = FD::table('File');
$table->name = $name;
$table->collection_id = $collectionId;
$table->hits = 0;
$table->hash = md5('tmp');
$table->uid = $this->uid;
$table->type = $this->type;
$table->created = JFactory::getDate()->toSql();
$table->user_id = FD::user()->id;
$table->size = filesize($file['tmp_name']);
$table->mime = $file['type'];
$table->state = SOCIAL_STATE_PUBLISHED;
$table->storage = SOCIAL_STORAGE_JOOMLA;
// Try to store the data on the database.
$table->store();
// Now we need to really upload the file.
$state = $table->storeWithFile($file);
// Format the data now
$result = $this->format(array($table));
return $result[0];
}
示例3: createAvatarFromFile
/**
* Allows caller to create an avatar by posted the $_FILE data
*
* @since 1.0
* @access public
* @param string
* @return
*/
public function createAvatarFromFile()
{
// Check for request forgeries
FD::checkToken();
// Only registered users should be allowed to upload photos
FD::requireLogin();
// Get the current view
$view = $this->getCurrentView();
$config = FD::config();
// Get the unique item id
$uid = JRequest::getInt('uid');
$type = JRequest::getCmd('type');
// Get current user.
$my = FD::user();
if (!$uid && !$type) {
$view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR);
return $view->call('createAvatar');
}
// Load up the photo library
$lib = FD::photo($uid, $type);
// Set uploader options
$options = array('name' => 'avatar_file', 'maxsize' => $lib->getUploadFileSizeLimit());
// Get uploaded file
$file = FD::uploader($options)->getFile();
// If there was an error getting uploaded file, stop.
if ($file instanceof SocialException) {
$view->setMessage($file);
return $view->call('createAvatar');
}
// Load the image
$image = FD::image();
$image->load($file['tmp_name'], $file['name']);
// Check if there's a profile photos album that already exists.
$albumModel = FD::model('Albums');
// Retrieve the default album for this node.
$album = $lib->getDefaultAlbum();
$photo = FD::table('Photo');
$photo->uid = $uid;
$photo->type = $type;
$photo->user_id = $my->id;
$photo->album_id = $album->id;
$photo->title = $file['name'];
$photo->caption = '';
$photo->ordering = 0;
// Set the creation date alias
$photo->assigned_date = FD::date()->toMySQL();
// We need to set the photo state to "SOCIAL_PHOTOS_STATE_TMP"
$photo->state = SOCIAL_PHOTOS_STATE_TMP;
// Try to store the photo first
$state = $photo->store();
// Bind any exif data if there are any.
// Only bind exif data for jpg files (if want to add tiff, then do add it here)
if ($image->hasExifSupport()) {
$photo->mapExif($file);
}
if (!$state) {
$view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_ERROR_CREATING_IMAGE_FILES'), SOCIAL_MSG_ERROR);
return $view->call('createAvatar');
}
// Push all the ordering of the photo down
$photosModel = FD::model('photos');
$photosModel->pushPhotosOrdering($album->id, $photo->id);
// Render photos library
$photoLib = FD::get('Photos', $image);
$storage = $photoLib->getStoragePath($album->id, $photo->id);
$paths = $photoLib->create($storage);
// Create metadata about the photos
foreach ($paths as $type => $fileName) {
$meta = FD::table('PhotoMeta');
$meta->photo_id = $photo->id;
$meta->group = SOCIAL_PHOTOS_META_PATH;
$meta->property = $type;
$meta->value = $storage . '/' . $fileName;
$meta->store();
}
// Retrieve the original photo again.
$image = $photo->getImageObject('original');
return $view->call('createAvatar', $photo);
}
示例4: addPhotoAlbum
public function addPhotoAlbum($log_usr = 0, $album_id)
{
$my = FD::user();
// Load up the configuration
$config = FD::config();
// Load the album table
$album = FD::table('Album');
$album->load($album_id);
// Check if the album id provided is valid
if (!$album->id || !$album->id) {
return "album not valid";
}
// Get the uid and the type
$uid = $album->uid;
$type = $album->type;
// Load the photo library
$lib = FD::photo($uid, $type);
// Set uploader options
$options = array('name' => 'file', 'maxsize' => $lib->getUploadFileSizeLimit());
// Get uploaded file
$file = FD::uploader($options)->getFile();
// If there was an error getting uploaded file, stop.
if ($file instanceof SocialException) {
return false;
}
// Load the image object
$image = FD::image();
$image->load($file['tmp_name'], $file['name']);
// Detect if this is a really valid image file.
if (!$image->isValid()) {
return false;
}
// Bind the photo data now
$photo = FD::table('Photo');
$photo->uid = $uid;
$photo->type = $type;
$photo->user_id = $album->uid;
$photo->album_id = $album->id;
$photo->title = $file['name'];
$photo->caption = '';
$photo->ordering = 0;
$photo->state = SOCIAL_STATE_PUBLISHED;
// Set the creation date alias
$photo->assigned_date = FD::date()->toMySQL();
// Cleanup photo title.
$photo->cleanupTitle();
// Trigger rules that should occur before a photo is stored
$photo->beforeStore($file, $image);
// Try to store the photo.
$state = $photo->store();
if (!$state) {
return false;
}
// If album doesn't have a cover, set the current photo as the cover.
//~ if (!$album->hasCover()) {
//~ $album->cover_id = $photo->id;
//~
//~ // Store the album
//~ $album->store();
//~ }
// Get the photos library
$photoLib = FD::get('Photos', $image);
// Get the storage path for this photo
$storageContainer = FD::cleanPath($config->get('photos.storage.container'));
$storage = $photoLib->getStoragePath($album->id, $photo->id);
$paths = $photoLib->create($storage);
// We need to calculate the total size used in each photo (including all the variants)
$totalSize = 0;
// Create metadata about the photos
if ($paths) {
foreach ($paths as $type => $fileName) {
$meta = FD::table('PhotoMeta');
$meta->photo_id = $photo->id;
$meta->group = SOCIAL_PHOTOS_META_PATH;
$meta->property = $type;
// do not store the container path as this path might changed from time to time
$tmpStorage = str_replace('/' . $storageContainer . '/', '/', $storage);
$meta->value = $tmpStorage . '/' . $fileName;
$meta->store();
// We need to store the photos dimension here
list($width, $height, $imageType, $attr) = getimagesize(JPATH_ROOT . $storage . '/' . $fileName);
// Set the photo size
$totalSize += filesize(JPATH_ROOT . $storage . '/' . $fileName);
// Set the photo dimensions
$meta = FD::table('PhotoMeta');
$meta->photo_id = $photo->id;
$meta->group = SOCIAL_PHOTOS_META_WIDTH;
$meta->property = $type;
$meta->value = $width;
$meta->store();
$meta = FD::table('PhotoMeta');
$meta->photo_id = $photo->id;
$meta->group = SOCIAL_PHOTOS_META_HEIGHT;
$meta->property = $type;
$meta->value = $height;
$meta->store();
}
}
// Set the total photo size
$photo->total_size = $totalSize;
//.........这里部分代码省略.........
示例5: upload
/**
* Allows caller to upload a photo
*
* @since 1.0
* @access public
* @param string
* @return
*/
public function upload()
{
// Check for request forgeries
FD::checkToken();
// Ensure that the user must be logged in
FD::requireLogin();
// Get the current view.
$view = $this->getCurrentView();
// Get the unique item stuffs
$uid = JRequest::getInt('uid');
$type = JRequest::getCmd('type');
if (!$uid && !$type) {
$view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR);
return $view->call(__FUNCTION__);
}
// Load the photo library now since we have the unique keys
$lib = FD::photo($uid, $type);
// Check if the user is allowed to upload cover photos
if (!$lib->canUploadCovers()) {
$view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_NO_PERMISSION_TO_UPLOAD_COVER'), SOCIAL_MSG_ERROR);
return $view->call(__FUNCTION__);
}
// Get the current logged in user.
$my = FD::user();
// Set uploader options
$options = array('name' => 'cover_file', 'maxsize' => $lib->getUploadFileSizeLimit());
// Get uploaded file
$file = FD::uploader($options)->getFile();
// If there was an error getting uploaded file, stop.
if ($file instanceof SocialException) {
$view->setMessage($file);
return $view->call(__FUNCTION__);
}
// Load the image
$image = FD::image();
$image->load($file['tmp_name'], $file['name']);
// Check if there's a profile photos album that already exists.
$model = FD::model('Albums');
// Retrieve the user's default album
$album = $model->getDefaultAlbum($uid, $type, SOCIAL_ALBUM_PROFILE_COVERS);
$photo = FD::table('Photo');
$photo->uid = $uid;
$photo->type = $type;
$photo->user_id = $my->id;
$photo->album_id = $album->id;
$photo->title = $file['name'];
$photo->caption = '';
$photo->ordering = 0;
$photo->assigned_date = FD::date()->toMySQL();
// Trigger rules that should occur before a photo is stored
$photo->beforeStore($file, $image);
// Try to store the photo.
$state = $photo->store();
if (!$state) {
$view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_ERROR_CREATING_IMAGE_FILES'), SOCIAL_MSG_ERROR);
return $view->call(__FUNCTION__);
}
// Trigger rules that should occur after a photo is stored
$photo->afterStore($file, $image);
// If album doesn't have a cover, set the current photo as the cover.
if (!$album->hasCover()) {
$album->cover_id = $photo->id;
// Store the album
$album->store();
}
// Render photos library
$photoLib = FD::get('Photos', $image);
$storage = $photoLib->getStoragePath($album->id, $photo->id);
$paths = $photoLib->create($storage);
// Create metadata about the photos
foreach ($paths as $type => $fileName) {
$meta = FD::table('PhotoMeta');
$meta->photo_id = $photo->id;
$meta->group = SOCIAL_PHOTOS_META_PATH;
$meta->property = $type;
$meta->value = $storage . '/' . $fileName;
$meta->store();
}
return $view->call(__FUNCTION__, $photo);
}