我无法在PHP中更新文件

时间:2018-10-29 07:08:54

标签: php file upload

我可以在其他页面上上传具有相同代码的文件。但是,当我使用此代码更新图像文件时,该文件只能为jpeg格式!我得到了错误。我在哪里犯错了?

该表还具有多个列。我只想更新“摄影”列。

<form action="" method="POST" enctype="multipart/form-data"> 
<input type="text" name="idi" value="<?PHP echo $cikti['id']; ?>">
<input type="file" name="resim" multiple="multiple"/></input><br><br>
<input type="submit" name="dosya" value="Change Image..." /></input>
</form>



<?php

if($_POST['idi']){
$degisecek_urun_id = $_POST['idi'];
if ($_FILES["resim"]["size"]<1024*1024){
if ($_FILES["resim"]["type"]=="image/jpg"){
$dosya_adi = $_FILES["resim"]["name"];

        $uret=array("as","rt","ty","yu","fg");
        $uzanti=substr($dosya_adi,-4,4);
        $sayi_tut=rand(1,10000000); 
        $yeni_adi="images/".$uret[rand(0,4)].$sayi_tut.$uzanti;
        if (move_uploaded_file($_FILES["resim"]["tmp_name"],$yeni_adi)){
            echo 'The file was uploaded successfully.';

        $sonuc = $db->exec("UPDATE urun_bilgileri SET foto = $yeni_adi WHERE id = $degisecek_urun_id");


       if ($sonuc){
        echo 'Saved to database.';

        }else{
            echo 'An error occurred while recording!';
        }
    }else{
        echo 'Failed to upload file!';
    }
}else{
       echo 'The file can only be in jpeg format!';
}
}else{          
    echo 'The file size cannot exceed 1 Mb!';
}


}

?>

1 个答案:

答案 0 :(得分:0)

在线号4编辑

    if ($_FILES["resim"]["type"]=="image/jpg")

替换为

    if ($_FILES["resim"]["type"]=="image/*")