本文整理汇总了PHP中Gdn_Upload::copyLocal方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Upload::copyLocal方法的具体用法?PHP Gdn_Upload::copyLocal怎么用?PHP Gdn_Upload::copyLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Upload
的用法示例。
在下文中一共展示了Gdn_Upload::copyLocal方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check
/**
* Do code checks on an uploaded addon.
*
* @param int $AddonID Addon to check.
* @param bool|false $SaveVersionID Whether to save the version id.
* @throws Exception Addon not found.
*/
public function check($AddonID, $SaveVersionID = false)
{
$this->permission('Addons.Addon.Manage');
if ($SaveVersionID !== false) {
// Get the version data.
$Version = $this->AddonModel->SQL->getWhere('AddonVersion', array('AddonVersionID' => $SaveVersionID))->firstRow(DATASET_TYPE_ARRAY);
$this->AddonModel->save($Version);
$this->Form->setValidationResults($this->AddonModel->validationResults());
}
$Addon = $this->AddonModel->getID($AddonID, false, ['GetVersions' => true]);
$AddonTypes = Gdn::sql()->get('AddonType')->resultArray();
$AddonTypes = Gdn_DataSet::index($AddonTypes, 'AddonTypeID');
if (!$Addon) {
throw notFoundException('Addon');
}
// Get the data for the most recent version of the addon.
$upload = new Gdn_Upload();
// Also used per version below.
$Path = $upload->copyLocal($Addon['File']);
$AddonData = arrayTranslate((array) $Addon, array('AddonID', 'AddonKey', 'Name', 'Type', 'Description', 'Requirements', 'Checked'));
try {
$FileAddonData = UpdateModel::analyzeAddon($Path);
if ($FileAddonData) {
$AddonData = array_merge($AddonData, arrayTranslate($FileAddonData, array('AddonKey' => 'File_AddonKey', 'Name' => 'File_Name', 'File_Type', 'Description' => 'File_Description', 'Requirements' => 'File_Requirements', 'Checked' => 'File_Checked')));
$AddonData['File_Type'] = valr($FileAddonData['AddonTypeID'] . '.Label', $AddonTypes, 'Unknown');
}
$upload->delete($Path);
} catch (Exception $Ex) {
$AddonData['File_Error'] = $Ex->getMessage();
}
$this->setData('Addon', $AddonData);
// Go through the versions and make sure we get the versions to check out.
$Versions = array();
foreach ($Addon['Versions'] as $Version) {
$Version = $Version;
$Path = $upload->copyLocal($Version['File']);
try {
$VersionData = arrayTranslate((array) $Version, array('AddonVersionID', 'Version', 'AddonKey', 'Name', 'MD5', 'FileSize', 'Checked'));
$FileVersionData = UpdateModel::analyzeAddon($Path);
$FileVersionData = arrayTranslate($FileVersionData, array('Version' => 'File_Version', 'AddonKey' => 'File_AddonKey', 'Name' => 'File_Name', 'MD5' => 'File_MD5', 'FileSize' => 'File_FileSize', 'Checked' => 'File_Checked'));
$upload->delete($Path);
} catch (Exception $Ex) {
$FileVersionData = array('File_Error' => $Ex->getMessage());
}
$Versions[] = array_merge($VersionData, $FileVersionData);
}
$this->setData('Versions', $Versions);
$this->addModule('AddonHelpModule');
$this->render();
}
示例2: utilityController_mediaThumbnail_create
/**
* Create and display a thumbnail of an uploaded file.
*/
public function utilityController_mediaThumbnail_create($sender, $media_id)
{
// When it makes it into core, it will be available in
// functions.general.php
require 'generate_thumbnail.php';
$model = new Gdn_Model('Media');
$media = $model->getID($media_id, DATASET_TYPE_ARRAY);
if (!$media) {
throw notFoundException('File');
}
// Get actual path to the file.
$local_path = Gdn_Upload::copyLocal($media['Path']);
if (!file_exists($local_path)) {
throw notFoundException('File');
}
$file_extension = pathinfo($local_path, PATHINFO_EXTENSION);
// Generate new path for thumbnail
$thumb_path = $this->getBaseUploadDestinationDir() . '/' . 'thumb';
// Grab full path with filename, and validate it.
$thumb_destination_path = $this->getAbsoluteDestinationFilePath($local_path, $file_extension, $thumb_path);
// Create thumbnail, and grab debug data from whole process.
$thumb_payload = generate_thumbnail($local_path, $thumb_destination_path, array('height' => c('Plugins.FileUpload.ThumbnailHeight', 128)));
if ($thumb_payload['success'] === true) {
// Thumbnail dimensions
$thumb_height = round($thumb_payload['result_height']);
$thumb_width = round($thumb_payload['result_width']);
// Move the thumbnail to its proper location. Calling SaveAs with
// cloudfiles enabled will trigger the move to cloudfiles, so use
// same path for each arg in SaveAs. The file will be removed from the local filesystem.
$parsed = Gdn_Upload::parse($thumb_destination_path);
$target = $thumb_destination_path;
// $parsed['Name'];
$Upload = new Gdn_Upload();
$filepath_parsed = $Upload->saveAs($thumb_destination_path, $target, array('source' => 'content'));
// Save thumbnail information to DB.
$model->save(array('MediaID' => $media_id, 'StorageMethod' => $filepath_parsed['Type'], 'ThumbWidth' => $thumb_width, 'ThumbHeight' => $thumb_height, 'ThumbPath' => $filepath_parsed['SaveName']));
// Remove cf scratch copy, typically in cftemp, if there was actually a file pulled in from CF.
if (strpos($local_path, 'cftemp') !== false) {
if (!unlink($local_path)) {
// Maybe add logging for local cf copies not deleted.
}
}
$url = $filepath_parsed['Url'];
} else {
// Fix the thumbnail information so this isn't requested again and again.
$model->save(array('MediaID' => $media_id, 'ImageWidth' => 0, 'ImageHeight' => 0, 'ThumbPath' => ''));
$url = asset('/plugins/FileUpload/images/file.png');
}
redirect($url, 301);
}
示例3: defaultAvatar
/**
* Settings page for uploading, deleting and cropping the default avatar.
*
* @throws Exception
*/
public function defaultAvatar()
{
$this->permission('Garden.Community.Manage');
$this->addSideMenu('dashboard/settings/avatars');
$this->title(t('Default Avatar'));
$this->addJsFile('avatars.js');
$validation = new Gdn_Validation();
$configurationModel = new Gdn_ConfigurationModel($validation);
$this->Form->setModel($configurationModel);
if (($avatar = c('Garden.DefaultAvatar')) && $this->isUploadedDefaultAvatar($avatar)) {
//Get the image source so we can manipulate it in the crop module.
$upload = new Gdn_Upload();
$thumbnailSize = c('Garden.Thumbnail.Size', 40);
$source = $upload->copyLocal(trim(changeBasename($avatar, "p%s"), 'uploads'));
//Set up cropping.
$crop = new CropImageModule($this, $this->Form, $thumbnailSize, $thumbnailSize, $source);
$crop->setExistingCropUrl(changeBasename($avatar, "n%s"));
$crop->setSourceImageUrl(changeBasename($avatar, "p%s"));
$this->setData('crop', $crop);
} else {
$this->setData('avatar', UserModel::getDefaultAvatarUrl());
}
if (!$this->Form->authenticatedPostBack()) {
$this->Form->setData($configurationModel->Data);
} else {
if ($this->Form->save() !== false) {
$upload = new Gdn_UploadImage();
$newAvatar = false;
if ($tmpAvatar = $upload->validateUpload('DefaultAvatar', false)) {
// New upload
$thumbOptions = array('Crop' => true, 'SaveGif' => c('Garden.Thumbnail.SaveGif'));
$newAvatar = $this->saveDefaultAvatars($tmpAvatar, $thumbOptions);
} else {
if ($avatar && $crop && $crop->isCropped()) {
// New thumbnail
$tmpAvatar = $source;
$thumbOptions = array('Crop' => true, 'SourceX' => $crop->getCropXValue(), 'SourceY' => $crop->getCropYValue(), 'SourceWidth' => $crop->getCropWidth(), 'SourceHeight' => $crop->getCropHeight());
$newAvatar = $this->saveDefaultAvatars($tmpAvatar, $thumbOptions);
}
}
if ($this->Form->errorCount() == 0) {
if ($newAvatar) {
$this->deleteDefaultAvatars($avatar);
$avatar = c('Garden.DefaultAvatar');
$thumbnailSize = c('Garden.Thumbnail.Size', 40);
// Update crop properties.
$source = $upload->copyLocal(trim(changeBasename($avatar, "p%s"), 'uploads'));
$crop = new CropImageModule($this, $this->Form, $thumbnailSize, $thumbnailSize, $source);
$crop->setSize($thumbnailSize, $thumbnailSize);
$crop->setExistingCropUrl(changeBasename($avatar, "n%s"));
$crop->setSourceImageUrl(changeBasename($avatar, "p%s"));
$this->setData('crop', $crop);
}
}
$this->informMessage(t("Your settings have been saved."));
}
}
$this->render();
}