【发布时间】:2018-10-29 07:08:54
【问题描述】:
我可以在不同的页面上上传具有相同代码的文件。但是当我使用这段代码更新图像文件时,文件只能是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!';
}
}
?>
【问题讨论】:
-
当你说 我得到错误 - 它说什么并且它是否指示任何行号?
-
是否打印错误代码?
-
如果显示有错误,请将其添加到您的问题中。
-
仅,注意:session_start():会话已经开始 - 忽略 /home/akayecza/public_html/ana_header.php 第 40 行
-
您应该考虑在 SQL 中使用准备好的语句,但您的问题可能是当您的 SQL 中包含字符字段时,您需要在值周围加上引号 -
foto = '$yeni_adi'