本文整理汇总了PHP中Gdn_Upload::getUploadedFileName方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Upload::getUploadedFileName方法的具体用法?PHP Gdn_Upload::getUploadedFileName怎么用?PHP Gdn_Upload::getUploadedFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Upload
的用法示例。
在下文中一共展示了Gdn_Upload::getUploadedFileName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postController_editorUpload_create
/**
*
*
* @param PostController $Sender
* @param array $Args
*/
public function postController_editorUpload_create($Sender, $Args = array())
{
// @Todo Move to a library/functions file.
require 'generate_thumbnail.php';
// Grab raw upload data ($_FILES), essentially. It's only needed
// because the methods on the Upload class do not expose all variables.
$fileData = Gdn::request()->getValueFrom(Gdn_Request::INPUT_FILES, $this->editorFileInputName, false);
$discussionID = $Sender->Request->post('DiscussionID') ? $Sender->Request->post('DiscussionID') : '';
// JSON payload of media info will get sent back to the client.
$json = array('error' => 1, 'feedback' => 'There was a problem.', 'errors' => array(), 'payload' => array());
// New upload instance
$Upload = new Gdn_Upload();
// This will validate, such as size maxes, file extensions. Upon doing
// this, $_FILES is set as a protected property, so all the other Gdn_Upload methods work on it.
$tmpFilePath = $Upload->validateUpload($this->editorFileInputName);
// Get base destination path for editor uploads
$this->editorBaseUploadDestinationDir = $this->getBaseUploadDestinationDir();
// Pass path, if doesn't exist, will create, and determine if valid.
$canUpload = Gdn_Upload::canUpload($this->editorBaseUploadDestinationDir);
if ($tmpFilePath && $canUpload) {
$fileExtension = strtolower($Upload->getUploadedFileExtension());
$fileName = $Upload->getUploadedFileName();
list($tmpwidth, $tmpheight, $imageType) = getimagesize($tmpFilePath);
// This will return the absolute destination path, including generated
// filename based on md5_file, and the full path. It
// will create a filename, with extension, and check if its dir can be writable.
$absoluteFileDestination = $this->getAbsoluteDestinationFilePath($tmpFilePath, $fileExtension);
// Save original file to uploads, then manipulate from this location if
// it's a photo. This will also call events in Vanilla so other plugins can tie into this.
if (empty($imageType)) {
$filePathParsed = $Upload->saveAs($tmpFilePath, $absoluteFileDestination, array('source' => 'content'));
} else {
$filePathParsed = Gdn_UploadImage::saveImageAs($tmpFilePath, $absoluteFileDestination, '', '', array('SaveGif' => true));
$tmpwidth = $filePathParsed['Width'];
$tmpheight = $filePathParsed['Height'];
}
// Determine if image, and thus requires thumbnail generation, or simply saving the file.
// Not all files will be images.
$thumbHeight = '';
$thumbWidth = '';
$imageHeight = '';
$imageWidth = '';
$thumbPathParsed = array('SaveName' => '');
$thumbUrl = '';
// This is a redundant check, because it's in the thumbnail function,
// but there's no point calling it blindly on every file, so just check here before calling it.
$generate_thumbnail = false;
if (in_array($fileExtension, array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'ico'))) {
$imageHeight = $tmpheight;
$imageWidth = $tmpwidth;
$generate_thumbnail = true;
}
// Save data to database using model with media table
$Model = new Gdn_Model('Media');
// Will be passed to model for database insertion/update. All thumb vars will be empty.
$Media = array('Name' => $fileName, 'Type' => $fileData['type'], 'Size' => $fileData['size'], 'ImageWidth' => $imageWidth, 'ImageHeight' => $imageHeight, 'ThumbWidth' => $thumbWidth, 'ThumbHeight' => $thumbHeight, 'InsertUserID' => Gdn::session()->UserID, 'DateInserted' => date('Y-m-d H:i:s'), 'StorageMethod' => 'local', 'Path' => $filePathParsed['SaveName'], 'ThumbPath' => $thumbPathParsed['SaveName']);
// Get MediaID and pass it to client in payload.
$MediaID = $Model->save($Media);
$Media['MediaID'] = $MediaID;
if ($generate_thumbnail) {
$thumbUrl = url('/utility/mediathumbnail/' . $MediaID, true);
}
$payload = array('MediaID' => $MediaID, 'Filename' => htmlspecialchars($fileName), 'Filesize' => $fileData['size'], 'FormatFilesize' => Gdn_Format::bytes($fileData['size'], 1), 'type' => $fileData['type'], 'Thumbnail' => '', 'FinalImageLocation' => '', 'Parsed' => $filePathParsed, 'Media' => (array) $Media, 'original_url' => $Upload->url($filePathParsed['SaveName']), 'thumbnail_url' => $thumbUrl, 'original_width' => $imageWidth, 'original_height' => $imageHeight);
$json = array('error' => 0, 'feedback' => 'Editor received file successfully.', 'payload' => $payload);
}
// Return JSON payload
echo json_encode($json);
}
示例2: handleAddonUpload
/**
* Handle form upload of an addon zip archive.
*
* @return array
*/
protected function handleAddonUpload()
{
$Upload = new Gdn_Upload();
$Upload->allowFileExtension(null);
$Upload->allowFileExtension('zip');
$AnalyzedAddon = [];
try {
// Validate the upload.
$TmpFile = $Upload->validateUpload('File');
$Extension = pathinfo($Upload->getUploadedFileName(), PATHINFO_EXTENSION);
// Generate the target name.
$TargetFile = $Upload->generateTargetName('addons', $Extension);
$TargetPath = PATH_UPLOADS . '/' . $TargetFile;
if (!file_exists(dirname($TargetPath))) {
mkdir(dirname($TargetPath), 0777, true);
}
// Save the file to a temporary location for parsing.
if (!move_uploaded_file($TmpFile, $TargetPath)) {
throw new Exception("We couldn't save the file you uploaded. Please try again later.", 400);
}
$AnalyzedAddon = UpdateModel::analyzeAddon($TargetPath, true);
// If the long description is blank, load up the readme if it exists
$formDescription = $this->Form->getFormValue('Description2', '');
if ($formDescription == '') {
$Readme = $this->parseReadme($TargetPath);
if ($Readme) {
$AnalyzedAddon['Description2'] = $Readme;
}
} else {
$AnalyzedAddon['Description2'] = $formDescription;
}
// Get an icon if one exists.
$Icon = $this->extractIcon($TargetPath, val('Icon', $AnalyzedAddon, ''));
if ($Icon) {
// Overwrite info array value with the path to the saved file.
$AnalyzedAddon['Icon'] = $Icon;
}
// Set the filename for the CDN.
$Upload->EventArguments['OriginalFilename'] = AddonModel::slug($AnalyzedAddon, true) . '.zip';
// Save the uploaded file. After this, we no longer have a local copy to analyze.
$Parsed = $Upload->saveAs($TargetPath, $TargetFile);
$AnalyzedAddon['File'] = $Parsed['SaveName'];
unset($AnalyzedAddon['Path']);
trace($AnalyzedAddon, 'Analyzed Addon');
$this->Form->formValues($AnalyzedAddon);
} catch (Exception $ex) {
$this->Form->addError($ex);
// Delete the erroneous file.
try {
if (isset($AnalyzedAddon) && isset($AnalyzedAddon['File'])) {
$Upload->delete($AnalyzedAddon['File']);
}
} catch (Exception $Ex2) {
}
}
if (isset($TargetPath) && file_exists($TargetPath)) {
unlink($TargetPath);
}
return $AnalyzedAddon;
}