2017-03-05 58 views
0

所以我一直在我的桌子上敲我的頭大約兩天,現在試圖找出是造成這個500錯誤。每次我嘗試發佈文件映像時,它都會引發一個錯誤:POST http://example.com/server/uploadProfile.php 500(內部服務器錯誤)來自PHP上傳腳本的500錯誤

不確定它意味着什麼以及如何去解決它。

<?php 

error_reporting(E_ALL); 
ini_set("display_errors", 1); 

function image_upload($max_size,$input_file,$path,$new_width) { 
if(!define("MAX_SIZE",$max_size)) { 
    define("MAX_SIZE",$max_size); 
} 

    $errors = 0; 



    if($_SERVER['REQUEST_METHOD'] == 'POST') { 

    $img = $_FILES[$input_file]['name']; 
    $tmp_file = $_FILES[$input_file]['tmp_name']; 

    } 

    if($img) { 

     $file_name = stripcslashes($_FILES[$input_file]['name']); 
     $extension = getExtension($file_name); 
     $extension = strtolower($extension); 


     if($extension != 'jpg' && $extension != 'jpeg' && $extension != 'png' && $extension != 'gif') { 
      //echo "Unknown image type."; 
      $errors = 1; 
      return "Wrong file type."; 
     } 
     else { 
      $size = filesize($_FILES[$input_file]['tmp_name']); 

      if($size > MAX_SIZE*1024) { 
       $error = 1; 
       return "File size too big"; 
       //echo "You have exceeded the size limit"; 
      } 

      if($extension == 'jpg' || $extension == 'jpeg') { 
       $uploadedfile = $_FILES[$input_file]['tmp_name']; 

       $src = imagecreatefromjpeg($uploadedfile); 
      } 
      else if($extension == 'png') { 
       $uploadedfile = $_FILES[$input_file]['tmp_name']; 
       $src = imagecreatefrompng($uploadedfile); 
      } 
      else if($extension == 'gif') { 
       $uploadedfile = $_FILES[$input_file]['tmp_name']; 
       $src = imagecreatefromgif($uploadedfile); 
      } 



      list($width,$height)=getimagesize($uploadedfile); 


      $newheight = ($height/$width)*$new_width; 


      $tmp = imagecreatetruecolor($new_width,$newheight); 


        imagecopyresampled($tmp,$src,0,0,0,0,$new_width,$newheight,$width,$height); 

      $rnd = rand(0,9999999999999999999999); 

      $file_name = $rnd.'_'.$_FILES[$input_file]['name']; 

      $upload_path = $path .$rnd.'_'.$_FILES[$input_file]['name'] 



      switch($_FILES[$input_file]['type']) { 
       case 'image/jpeg': 

         imagejpeg($tmp, $upload_path, 100); 


       break; 
       case 'image/jpg' : 

        imagejpeg($tmp, $upload_path, 100); 



       break; 
       case 'image/png': 

         imagepng($tmp, $upload_path, 0); 


       break; 
       case 'image/gif' : 

         imagegif($tmp, $upload_path); 
       break; 

      } 



     } 

    } 


} 

    function getExtension($str) { 

    $i = strrpos($str,"."); 
    if (!$i) { return ""; } 
    $l = strlen($str) - $i; 
    $ext = substr($str,$i+1,$l); 
    return $ext; 
    } 

    if(isset($_FILES['profilePhoto']['tmp_name'])) { 

    image_upload("320000","profilePhoto","/profile",250); 

    } 



?> 
+0

您在Apache錯誤日誌中有答案。請檢查它,或者至少粘貼在這裏可以看到什麼錯誤。谷歌關於你在哪裏可以找到它。 –

回答

1
$upload_path = $path .$rnd.'_'.$_FILES[$input_file]['name'] 

你缺少一個;在行末。使腳本無法編譯的語法錯誤將導致服務器錯誤500

+0

真的......大聲笑這就是它。謝謝。不知道我是如何繼續錯失這一點的。再次感謝! –