2014-02-25 43 views
0

我有以下的PHP腳本上傳圖片到我的網站:圖像不能因被訪問到「401未經授權:訪問被拒絕由於憑據無效」的錯誤消息

function saveImage2Server($input_name) 
{ 
    $originalFileName = basename($_FILES[$input_name]["name"]); 
    $fileType = exif_imagetype($_FILES[$input_name]["tmp_name"]); 
    $fileSize = $_FILES[$input_name]["size"]; 
    $allowedTypes = array(IMAGETYPE_JPEG, IMAGETYPE_PNG); 
    $maxSize = 819200; 

    // first check if the file is of allowed type 
    if(in_array($fileType, $allowedTypes)) 
    { 
     //check if the size is under 800kb 
     if($fileSize<=$maxSize) 
     { 
      $dotIndex = strrpos($originalFileName, "."); 
      $extension = strtolower(substr($originalFileName, $dotIndex)); 

      $newFileName = uniqid().uniqid().$extension; 
      move_uploaded_file($_FILES[$input_name]["tmp_name"], "../../images/".$newFileName); 
      return $newFileName; 
     } 
     else // if it's above 800kb 
     { 
      echo("The file size exceeds 800kb"); 
      header("Location: ../"); 
      die(error); 
     } 
    } 
    else // if the type isn't allowed 
    { 
     echo("This file type isn't allowed"); 
     header("Location: ../"); 
     die(error); 
    } 
} 

該腳本在我的本地服務器(WAMP)上正常工作,在文件上傳後,我可以正常訪問它們。但是,當在IIS上 - 文件正在上傳,但試圖訪問它們時,我得到這個401錯誤信息:401 - Unauthorized: Access is denied due to invalid credentials.

我可以或我的託管公司做什麼來解決它?

回答

1

確保IIS用戶具有對上載圖像的目錄的寫入權限。

+0

顯然,他們的授權繼承有問題。出於安全原因,他們也阻止了ini_set,所以我自己無法處理它。現在一切正常。謝謝您的回覆! – Igal

相關問題