I have almost filled up this signup form 30 times in a day debugging this and still the image is not reaching to the destination folder as it should. This code is present in htdocs/Email/signup.php and uploaded file should be moved to htdocs/gid113/Eagleeye/guard/imges/id.jpg and even only "id." is inserted in mysql database and not "id.jpg" unable to get the extension for image .


    if(isset($_POST['signup'])){
        $result = $conn->query("SHOW TABLE STATUS LIKE 'guard'");
        $data = mysqli_fetch_assoc($result);
        $id = $data['Auto_increment'];
        $_SESSION["id"] = $id;
        print_r($_FILES);

        // File Image handling while signup
        if($_FILES['img']['error']==UPLOAD_ERR_OK){
            $file_name = $_FILES['img']['name'];
            $file_size = $_FILES['img']['size'];
            $file_tmp = $_FILES['img']['tmp_name'];
            $file_type = $_FILES['img']['type'];
            $destination = "../gid113/Eagleeye/guard/imges/".basename($file_name);
            $file_extension = pathinfo($file_name, PATHINFO_EXTENSION);
            move_uploaded_file($file_tmp,$destination);
            // $new_name ="./imges/".$id.".".$file_extension;
            $new_name = id.".".$file_extension;
            rename($destination,$new_name);
            // $img=pathinfo($new_name,PATHINFO_BASENAME);
            $img=$new_name;
        }
    }
1

There are 1 best solutions below

1
On

SOLUTION:-

  1. Added $ before Id in $new_name declaration.
  2. Specified path to destination folder to the second parameter of rename as well.
if(isset($_FILES['img'])){
                $file_name = $_FILES['img']['name'];
                $file_size = $_FILES['img']['size'];
                $file_tmp = $_FILES['img']['tmp_name'];
                $file_type = $_FILES['img']['type'];
                $destination = "../gid113/Eagleeye/guard/imges/".basename($file_name);
                $file_extension = pathinfo($file_name, PATHINFO_EXTENSION);
                move_uploaded_file($file_tmp,$destination);
                // $new_name ="./imges/".$id.".".$file_extension;
                $new_name = $id.".".$file_extension;
                rename($destination,"../gid113/Eagleeye/guard/imges/".$new_name);
                // $img=pathinfo($new_name,PATHINFO_BASENAME);
                $img=$new_name;
}