2016-01-21 68 views
0

我有這個輸入型

<input class="btn btn-success" type="file" name="profile_image" style="margin-top:10px; margin-left:20px;"></input> 

用戶將在此處添加的圖像文件,並且PHP代碼上傳的文件

if(isset($_FILES['profile_image'])) 
      { 
       $image_type = $this->getImageType($_FILES['profile_image']); 

       if($image_type == 'image') 
       { 
        $extension = pathinfo($_FILES['profile_image']['name'], PATHINFO_EXTENSION); 
        $filename = '123_'.uniqid().'.'.$extension; 
        move_uploaded_file($_FILES['profile_image']['tmp_name'], '../functions/images/images/'.$filename); 
       } 
      } 
else 
      { 
       $filename = 'default_profile_image.jpg'; 
      } 

getImageType

public function getImageType($file) 
    { 
     $imageMime = getimagesize($file['tmp_name']); 
     $type = explode('/', $imageMime['mime']); 
     return $type[0]; 
    } 

,但它不讀取$_FILES['profile_image']和而移動到其他部分。爲什麼它不讀$ _FILES?有什麼遺漏嗎?

+1

也許你的''

標籤缺少'ENCTYPE = 「的multipart/form-data的」'屬性? [閱讀更多](http://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean)。 –

回答

6

形式標記添加此代碼
enctype="multipart/form-data"

<form action="upload.php" method="post" enctype="multipart/form-data">