2017-06-28 105 views
1

我檢查了php.ini文件上傳已打開。 以下是代碼請幫助我。 文件未上傳到文件夾圖像中。 我不知道代碼的問題是什麼。 問題不在於查詢,因爲(!empty($ _ FILES [「uploadedimage」] [「name」]))沒有上傳圖片。我使用PHP上傳圖片,但沒有上傳到文件夾?

<form enctype="multipart/form-data" method="post"> 
            <th><input style=" width:100px; font-size:13px" name="op" Placeholder="Operator Name"/></th> 
<th> <input class="file-upload-input" type="file" name="uploadedimage"></th> 

<th> <input class="btn btn-danger" type="submit" name="uploadnow" value="SUBMIT" class="theme-btn btn-style-one"></th> 


            </tr></form> 
           <?php 

    function GetImageExtension($imagetype) 
    { 
     if(empty($imagetype)) return false; 
     switch($imagetype) 
     { 
      case 'image/bmp': return '.bmp'; 
      case 'image/gif': return '.gif'; 
      case 'image/jpeg': return '.jpg'; 
      case 'image/png': return '.png'; 

      default: return false; 
     } 
    } 

if (!empty($_FILES["uploadedimage"]["name"])) { 

    $file_name=$_FILES["uploadedimage"]["name"]; 
    $temp_name=$_FILES["uploadedimage"]["tmp_name"]; 
    $imgtype=$_FILES["uploadedimage"]["type"]; 
    $ext= GetImageExtension($imgtype); 
    $imagename=date("d-m-Y")."-".time().$ext; 
    $target_path = "images/".$imagename;  
if($_POST['uploadnow']) 
{ 
$op=$_POST['op']; 
if(move_uploaded_file($temp_name, $target_path)) { 
    $sql="INSERT INTO operator(op,mono) VALUES('".$op."','".$target_path."') "; 
    mysql_query($sql) or die 
    ("error in $query_upload == ----> ".mysql_error()); 
    } 
} 

?> <script type="text/javascript"> 
document.location.href='operator.php'; 
</script> 
<?php 

} 
?> 
+0

數據被保存在db – Rahul

+0

您的代碼似乎正確..檢查文件夾權限。 – lalithkumar

回答

0

嘗試使用$ target_path =「/images/".$imagename;

+0

我檢查,但不工作,你可以請重新檢查代碼 – Saddam

+0

該代碼看起來合法,嘗試調試。試試echo「join」if(!empty($ _ FILES [「uploadedimage」] [「name」])){ – MorganFreeFarm

0

嘗試將這些行放在代碼的頂部,以顯示所有PHP錯誤/警告並查看所得結果。

error_reporting(E_ALL); 
ini_set('display_errors', 1); 
相關問題