本文整理匯總了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 = val('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 = val('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, val('Height', $Options, ''), val('Width', $Options, ''), $Options);
trace($Parsed, 'Saved Image');
$Current = $this->getFormValue($Field);
if ($Current && val('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);
}
}