Home » Php » php – Upload image system problem. Cant upload image

php – Upload image system problem. Cant upload image

Posted by: admin February 25, 2020 Leave a comment

Questions:

I build a upload image system to database on PHP.
when I try to upload image its don’t work and show me all time same message
“Image already exists”.

if(isset($_POST['project_save'])) {
$title = $_POST['wTitle'];
$description = $_POST['wDescription'];
$link = $_POST['wLink'];
$image = $_FILES["wImage"]["wTitle"];

if(file_exists("upload/" . $_FILES["wImage"]["wTitle"])) {
    $store = $_FILES["wImage"]["wTitle"];
    $_SESSION['status'] = "Image Already Exists. '.$store.'";
    header("Location: portfolio.php");
} else {
    $query = "INSERT INTO portfolio ('title', 'description', 'link', 'image') VALUES ('$title', '$description', '$link', '$image)";
    $query_run = mysqli_query($connection, $query);

    if($query_run) {
        move_uploaded_file($_FILES["wImage"]["tmp_wTitle"], "upload/".$_FILES["wImage"]["wTitle"]);
        $_SESSION['success'] = "Image Added";
        header("Location: portfolio.php");
    } else {
        $_SESSION['success'] = "Image Not Added";
        header("Location: portfolio.php");
    }
}

}

on portfolio.php:
if(isset($_SESSION['success']) && $_SESSION['success'] !='') {
    echo '<h2>'.$_SESSION['success'].'</h2>';
    unset($_SESSION['success']);
}

if(isset($_SESSION['status']) && $_SESSION['status'] !='') {
    echo '<h2>'.$_SESSION['status'].'</h2>';
    unset($_SESSION['status']);
}   
?>

I passed on the code and don’t see problem, if you see please help me to fix it.
thanks !

How to&Answers: