我正在寫查詢接受圖像字段只有svg,png,jpeg format.But如果圖像字段爲空,它顯示爲上傳時的錯誤,實際上它應該插入剩餘的字段,如名稱和所有如果我不添加圖像also.Here是我的查詢。應該接受數據如果圖像字段爲空使用php
使用example.php
$title=$_POST['blog_title'];
$result = str_replace(" ", "-", $title);
$description=$_POST['blog_description'];
if(is_uploaded_file($_FILES['image']['tmp_name'])){
$name=$_FILES["image"]["name"];
$type=$_FILES["image"]["type"];
$size=$_FILES["image"]["size"];
$temp=$_FILES["image"]["tmp_name"];
$error=$_FILES["image"]["error"];
$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
if($error > 0){
die("error while uploading");
}else{
$permissible_extension = array("png", "jpg", "jpeg", "svg", "jpg","jpe");
if(in_array($ext, $permissible_extension)){
if(move_uploaded_file($temp,"upload/".$name)){
$sql = mysql_query("INSERT INTO blogs(image,blog_title,blog_description)values('$name','$result','$description')");
if($sql){
header("Location:blogimage.php");
exit();
}else{
echo "Insertion failed";
}
}else{
echo "File couldn't be uploaded";
}
}else{
echo "Invalid format";
}
}
}else{
$sql = mysql_query("INSERT INTO blogs(blog_title,blog_description)values('$result','$description')");
if($sql){
header("Location:blogimage.php");
exit();
}else{
echo "Insertion failed";
}
}
「**應該上傳的圖片,如果沒有圖像**」它是有意義的嗎? –
如果iam沒有添加圖片,我提交了記錄,那麼它應該插入正確的東西,這對你有意義嗎? – user5891511
你能跟我們分享顯示的錯誤嗎? – drosam