本文整理汇总了PHP中Gdn_Upload::AllowFileExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Upload::AllowFileExtension方法的具体用法?PHP Gdn_Upload::AllowFileExtension怎么用?PHP Gdn_Upload::AllowFileExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Upload
的用法示例。
在下文中一共展示了Gdn_Upload::AllowFileExtension方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: UploadFile
function UploadFile($TargetFolder, $InputName, $Options = False)
{
/* if (is_array($InputName)) {
$Options = $InputName;
$InputName = $TargetFolder;
}*/
$FileName = ArrayValue('name', ArrayValue($InputName, $_FILES));
if ($FileName == '') {
return;
}
// no upload, return null
// options
$AllowFileExtension = ArrayValue('AllowFileExtension', $Options);
// TODO: $Overwrite is not used yet
$CanOverwrite = ArrayValue('Overwrite', $Options, False);
$CreateTargetFolder = ArrayValue('CreateTargetFolder', $Options, True);
$WebTarget = ArrayValue('WebTarget', $Options);
if ($CreateTargetFolder === True) {
if (!file_exists($TargetFolder)) {
mkdir($TargetFolder, 0777, True);
}
if (!is_writable($TargetFolder)) {
throw new Exception(sprintf('Directory (%s) is not writable.', $TargetFolder));
}
}
$Upload = new Gdn_Upload();
if ($AllowFileExtension != False) {
if (!is_array($AllowFileExtension)) {
$AllowFileExtension = SplitString($AllowFileExtension);
}
foreach ($AllowFileExtension as $Extension) {
$Upload->AllowFileExtension($Extension);
}
}
$IsMultipleUpload = is_array($FileName);
$Count = $IsMultipleUpload ? count($FileName) : 1;
$OriginalFiles = $_FILES;
$Result = array();
for ($i = 0; $i < $Count; $i++) {
if ($IsMultipleUpload != False) {
$_FILES[$InputName] = array();
foreach (array('name', 'type', 'tmp_name', 'error', 'size') as $Key) {
$Value = GetValueR($InputName . '.' . $Key . '.' . $i, $OriginalFiles);
SetValue($Key, $_FILES[$InputName], $Value);
}
} else {
$FileName = array($FileName);
}
$TempFile = $Upload->ValidateUpload($InputName);
$TargetFile = GenerateCleanTargetName($TargetFolder, $FileName[$i], '', $TempFile, $CanOverwrite);
// 2.0.18 screwed Gdn_Upload::SaveAs()
//$Upload->SaveAs($TempFile, $TargetFile);
if (!move_uploaded_file($TempFile, $TargetFile)) {
throw new Exception(sprintf(T('Failed to move uploaded file to target destination (%s).'), $TargetFile));
}
if ($WebTarget != False) {
$File = str_replace(DS, '/', $TargetFile);
} elseif (array_key_exists('WithTargetFolder', $Options)) {
$File = $TargetFile;
} else {
$File = pathinfo($TargetFile, PATHINFO_BASENAME);
}
$Result[] = $File;
}
$_FILES = $OriginalFiles;
if ($IsMultipleUpload) {
return $Result;
}
return $File;
}