搜尋
首頁php教程PHP源码php文件上传经典代码

<script>ec(2);</script>

php文件上传经典代码

function FileUpload( $resourceType, $currentFolder, $sCommand )
{
 if (!isset($_FILES)) {
  global $_FILES;
 }
 $sErrorNumber = '0' ;
 $sFileName = '' ;

 if ( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) )
 {
  global $Config ;

  $oFile = $_FILES['NewFile'] ;

  // Map the virtual path to the local server path.
  $sServerDir = ServerMapFolder( $resourceType, $currentFolder, $sCommand ) ;

  // Get the uploaded file name.
  $sFileName = $oFile['name'] ;
  $sFileName = SanitizeFileName( $sFileName ) ;

  $sOriginalFileName = $sFileName ;

  // Get the extension.
  $sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
  $sExtension = strtolower( $sExtension ) ;

  if ( isset( $Config['SecureImageUploads'] ) )
  {
   if ( ( $isImageValid = IsImageValid( $oFile['tmp_name'], $sExtension ) ) === false )
   {
    $sErrorNumber = '202' ;
   }
  }

  if ( isset( $Config['HtmlExtensions'] ) )
  {
   if ( !IsHtmlExtension( $sExtension, $Config['HtmlExtensions'] ) &&
    ( $detectHtml = DetectHtml( $oFile['tmp_name'] ) ) === true )
   {
    $sErrorNumber = '202' ;
   }
  }

  // Check if it is an allowed extension.
  if ( !$sErrorNumber && IsAllowedExt( $sExtension, $resourceType ) )
  {
   $iCounter = 0 ;

   while ( true )
   {
    $sFilePath = $sServerDir . $sFileName ;

    if ( is_file( $sFilePath ) )
    {
     $iCounter++ ;
     $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;
     $sErrorNumber = '201' ;
    }
    else
    {
     move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;

     if ( is_file( $sFilePath ) )
     {
      if ( isset( $Config['ChmodOnUpload'] ) && !$Config['ChmodOnUpload'] )
      {
       break ;
      }

      $permissions = 0777;

      if ( isset( $Config['ChmodOnUpload'] ) && $Config['ChmodOnUpload'] )
      {
       $permissions = $Config['ChmodOnUpload'] ;
      }

      $oldumask = umask(0) ;
      chmod( $sFilePath, $permissions ) ;
      umask( $oldumask ) ;
     }

     break ;
    }
   }

   if ( file_exists( $sFilePath ) )
   {
    //previous checks failed, try once again
    if ( isset( $isImageValid ) && $isImageValid === -1 && IsImageValid( $sFilePath, $sExtension ) === false )
    {
     @unlink( $sFilePath ) ;
     $sErrorNumber = '202' ;
    }
    else if ( isset( $detectHtml ) && $detectHtml === -1 && DetectHtml( $sFilePath ) === true )
    {
     @unlink( $sFilePath ) ;
     $sErrorNumber = '202' ;
    }
   }
  }
  else
   $sErrorNumber = '202' ;
 }
 else
  $sErrorNumber = '202' ;


 $sFileUrl = CombinePaths( GetResourceTypePath( $resourceType, $sCommand ) , $currentFolder ) ;
 $sFileUrl = CombinePaths( $sFileUrl, $sFileName ) ;

 SendUploadResults( $sErrorNumber, $sFileUrl, $sFileName ) ;

 exit ;

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具