本文整理汇总了PHP中Gdn_UploadImage::GetUploadedFileExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_UploadImage::GetUploadedFileExtension方法的具体用法?PHP Gdn_UploadImage::GetUploadedFileExtension怎么用?PHP Gdn_UploadImage::GetUploadedFileExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_UploadImage
的用法示例。
在下文中一共展示了Gdn_UploadImage::GetUploadedFileExtension方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: SaveImage
/**
* Save an image from a field and delete any old image that's been uploaded.
*
* @param string $Field The name of the field. The image will be uploaded with the _New extension while the current image will be just the field name.
* @param array $Options
*/
public function SaveImage($Field, $Options = array())
{
$Upload = new Gdn_UploadImage();
$FileField = str_replace('.', '_', $Field);
if (!GetValueR("{$FileField}_New.name", $_FILES)) {
Trace("{$Field} not uploaded, returning.");
return FALSE;
}
// First make sure the file is valid.
try {
$TmpName = $Upload->ValidateUpload($FileField . '_New', TRUE);
if (!$TmpName) {
return FALSE;
}
// no file uploaded.
} catch (Exception $Ex) {
$this->AddError($Ex);
return FALSE;
}
// Get the file extension of the file.
$Ext = GetValue('OutputType', $Options, trim($Upload->GetUploadedFileExtension(), '.'));
if ($Ext == 'jpeg') {
$Ext = 'jpg';
}
Trace($Ext, 'Ext');
// The file is valid so let's come up with its new name.
if (isset($Options['Name'])) {
$Name = $Options['Name'];
} elseif (isset($Options['Prefix'])) {
$Name = $Options['Prefix'] . md5(microtime()) . '.' . $Ext;
} else {
$Name = md5(microtime()) . '.' . $Ext;
}
// We need to parse out the size.
$Size = GetValue('Size', $Options);
if ($Size) {
if (is_numeric($Size)) {
TouchValue('Width', $Options, $Size);
TouchValue('Height', $Options, $Size);
} elseif (preg_match('`(\\d+)x(\\d+)`i', $Size, $M)) {
TouchValue('Width', $Options, $M[1]);
TouchValue('Height', $Options, $M[2]);
}
}
Trace($Options, "Saving image {$Name}.");
try {
$Parsed = $Upload->SaveImageAs($TmpName, $Name, GetValue('Height', $Options, ''), GetValue('Width', $Options, ''), $Options);
Trace($Parsed, 'Saved Image');
$Current = $this->GetFormValue($Field);
if ($Current && GetValue('DeleteOriginal', $Options, TRUE)) {
// Delete the current image.
Trace("Deleting original image: {$Current}.");
if ($Current) {
$Upload->Delete($Current);
}
}
// Set the current value.
$this->SetFormValue($Field, $Parsed['SaveName']);
} catch (Exception $Ex) {
$this->AddError($Ex);
}
}