當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。