-1
<?php


    if (isset($_POST['submit'])) {
        $title = $_POST['title'];

        if (isset($_FILES['images']['name'])) {
            $image_name = $_FILES['images']['name'];
            echo($image_name);
            $image_path = $_FILES['images']['tmp_name'];
            echo($image_path);
            $destination_path = 'location:'.SITEURL.'images/category/'.$image_name;
            // echo($destination_path);
            $upload = move_uploaded_file($image_name, $destination_path);
            echo($upload);

            if ($upload==0) {
                $_SESSION['upload_image_category'] = "<div class='error'>failed to upload image </div>";
                header('location:'.SITEURL.'admin/add-category.php');
                die();
            }
        }
        else{
            $image_name = "";
        }

        if (isset($_POST['featureyon'])) {
            $feature = $_POST['featureyon'];
        }
        else{
            $feature = "No";
        }

        if (isset($_POST['a_yes'])) {
            $active = $_POST['a_yes'];
        }
        else{
            $active = "No";
        }
        
        # code...
        $sql = "INSERT INTO tbl_category SET 
            title = '$title',
            image_name='$image_name', 
            featured='$feature', 
            active='$active'
        ";
        $res = mysqli_query($conn, $sql);
        if ($res == True) {
            $_SESSION['add_category'] =  "<div class='success'>New category added</div>";
            header('location:'.SITEURL.'admin/manage_category.php');
        }
        else{
            $_SESSION['add_category'] = "<div class='error'>failed to add New category </div>";
            header('location:'.SITEURL.'admin/add-category.php');
        }
    }
?>
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Please provide more information as to what exactly is or isn't happening and when. Let us know what you have tried. – Kyle Aug 30 '22 at 20:15
  • Why do you have `location:` in `$destination_path`? That's not part of the pathname. – Barmar Aug 30 '22 at 20:15
  • What did your [**PHP error logs**](https://stackoverflow.com/questions/5127838/where-does-php-store-the-error-log-php-5-apache-fastcgi-and-cpanel?noredirect=1&lq=1) tell you? – Martin Aug 30 '22 at 20:15
  • `$destination_path` should be a real pathname on the server, not a URL. – Barmar Aug 30 '22 at 20:16
  • when try to upload image i get this error **if ($upload==0) { $_SESSION['upload_image_category'] = "
    failed to upload image
    "; header('location:'.SITEURL.'admin/add-category.php'); die(); }** failed to upload image
    – Mohamed Abdiaziz Aug 30 '22 at 20:24
  • Ok, so that means `move_uploaded_file` returned false. Now you need to trace back again to work out why that might have happened. – ADyson Aug 30 '22 at 21:10

1 Answers1

0

the first

$destination_path should be a real pathname on the server, not a URL. Like this :- $destination_path = '../images/category/'.$image_name;

the second

move_uploaded_file(source_path, destination_path) Like this :- $upload = move_uploaded_file($image_path, $destination_path);