2015-03-13 99 views
1

我想在檢查圖像大小,寬度和高度後上傳圖像,但我的腳本有錯誤。檢查大小,寬度和高度後上傳圖像

代碼:

<?php 
    include('dbcon.php'); 
    $name=$_POST["name"]; 
    $tel=$_POST["tel"]; 

    //upload file syntax begining 
    $fileField=$_FILES["fileField"]["name"]; 

    if($_FILES["fileField"]["size"] >= 50000) { 
    echo "bigfile"; 
    } 
    elseif { 
    $fileField = @getimagesize($_FILES["fileField"]["tmp_name"]); 
    ($fileField === FALSE || !($fileField[2] == IMAGETYPE_GIF || $fileField[2] == IMAGETYPE_JPEG || $fileField[2] == IMAGETYPE_PNG)); 
    echo "Only Allow jpeg,PNG,Gif"; 

    { 
    else{ 
    move_uploaded_file($_FILES["fileField"]["tmp_name"],"upload/".$_FILES["fileField"]["name"]); 
    //upload file syntax ending 
    $sql="insert into imgtb(name,tel,image)values('$name','$tel','$fileField')"; 
    $result=mysql_query($sql); 
    } 
?> 

有人請幫助修正錯誤!

回答

1

您的代碼更改爲以下:

<?php 
include('dbcon.php'); 
$name = $_POST["name"]; 
$tel = $_POST["tel"]; 

$fileField = $_FILES["fileField"]["name"]; 

if($_FILES["fileField"]["size"] >= 50000) { 
    echo "big image"; 
} else { 
    $fileField = @getimagesize($_FILES["fileField"]["tmp_name"]); 
    if ($fileField === FALSE || !($fileField[2] == IMAGETYPE_GIF || $fileField[2] == IMAGETYPE_JPEG || $fileField[2] == IMAGETYPE_PNG)) { 
     echo "Only Allow jpeg,PNG,Gif"; 
    } else { 
     move_uploaded_file($_FILES["fileField"]["tmp_name"],"upload/".$_FILES["fileField"]["name"]); 

     $sql="insert into imgtb(name,tel,image)values('$name','$tel','$fileField')"; 
     $result=mysql_query($sql); 
    } 
} 
?> 

注意:你有這麼多的語法錯誤。在插入數據庫之前將所有變量轉義。

相關問題