当前位置: 首页>>代码示例>>PHP>>正文


PHP Gdn_Upload::AllowFileExtension方法代码示例

本文整理汇总了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;
 }
开发者ID:ru4,项目名称:arabbnota,代码行数:70,代码来源:functions.file.php


注:本文中的Gdn_Upload::AllowFileExtension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。