私はそのフォームでいくつかの入力を持つフォームを持っています。空白に置き換えないようにするために、画像をデータベースに保存しておきたい。入力が空の場合、条件分岐以外の場合はエラーecho "Sorry, there was an error uploading your file.";
からエラーが発生します。画像をアップロードすると、すべて正常に動作します。ここに私のコードです入力画像が空の場合エラーが発生する
<?php
include "../../../config/config.php";
session_start();
if (isset($_GET['car'])) {
$car = $_GET['car'];
} else {
die("Not found");
}
if (isset($_POST['submit-edit'])) {
$title = mysqli_real_escape_string($con, $_POST['title-edit']);
$description = mysqli_real_escape_string($con, $_POST['description-edit']);
$category = mysqli_real_escape_string($con, $_POST['category-edit']);
/* ----------------------- MAIN IMAGE -------------------------- */
$target_dir = "../../../img/found/thumbs-category/";
$target_file2 = "" . basename($_FILES["img-edit"]["name"]);
$target_file = $target_dir . basename($_FILES["img-edit"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
// Check file size
if ($_FILES["img-edit"]["size"] > 100000) {
$_SESSION['image-size'] = 1;
header("Location: /dashboard/views/edit.php?car=$car");
exit();
}
//
//Allow certain file formats
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" && $imageFileType != NULL) {
$_SESSION['image-format'] = 1;
header("Location: /dashboard/views/edit.php?car=$car");
exit();
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
} else {
if (move_uploaded_file($_FILES["img-edit"]["tmp_name"], $target_file)) {
} else {
echo "Sorry, there was an error uploading your file.";
exit();
}
$query = "UPDATE cars
SET title='" . $title . "', text='" . $description . "', image='" . $target_file2 . "', fk_cars_first='" . $category . "' WHERE car=" . $car;
$result = mysqli_query($con, $query);
// var_dump($query);
// exit();
if ($result) {
header("Location: /dashboard/views/edit.php?car=$car");
} else {
//
echo "error";
exit();
header("Location: /dashboard/views/edit.php?car=$car");
}
}
}
?>
もっと私はフォームを使用し、タイプ=「ファイル」と入力が空の私がある場合は、データベースを編集したい場合は、正確に私のデータベースに私が
title | description | image | fk_category test more text car.jpg tuning
を持っています右のコード..消去しないように、実際のパスを維持したいthis..Iような何かを送信ボタンを設定し、取得エラーSorry, there was an error uploading your file.
と、データベース内のパス空の場合、データベースが
title | description | image | fk_category testedited | ed!t | | tuning_tex_edited
のように見えます空白です。