Mohsin Younas
Mohsin Younas

Reputation: 11

Failed to upload the image in mysql server

I have uploaded the project on the server every thing is working fine except for the few things.

I am not able to uplaod the file images on the server please check the errors.

I have even set the permission to 777.

Warning: move_uploaded_file(../images/fail to upload.jpg): failed to open stream: No such file or directory in /srv/disk14/2293074/www/cms.mohsinyounas.info/admin/includes/add_posts.php on line 15

Warning: move_uploaded_file(): Unable to move '/tmp/phpx2WZ8c' to '../images/fail to upload.jpg' in /srv/disk14/2293074/www/cms.mohsinyounas.info/admin/includes/add_posts.php on line 15

Thank you.

<?php
        include "./function.php";
        global $con;

        if(isset($_POST['create_post'])) {
            $post_image      = $_FILES['post_image']['name'];
            $post_image_temp = $_FILES['post_image']['tmp_name'];

            move_uploaded_file("$post_image_temp","../images/$post_image");

            $sql    = "INSERT INTO posts (post_image) VALUES ('$post_image')";
            $result = mysqli_query($con,$sql);
            confirm($result);
        }
?>

Upvotes: 0

Views: 71

Answers (1)

ImBhavin95
ImBhavin95

Reputation: 1527

Change this code you have to remove "" from variable in move_uploaded_file()

<?php
    include "./function.php";
    global $con;
    if(isset($_POST['create_post'])) {
        $post_image =$_FILES['post_image']['name'];
        $post_image_temp =$_FILES['post_image']['tmp_name'];
        $path = "../images/".$post_image;
        move_uploaded_file($post_image_temp,$path);
        $sql = "INSERT INTO posts (post_image)
                VALUES ('$post_image')";
        $result=mysqli_query($con,$sql);
        confirm($result);
    }
?>

Upvotes: 1

Related Questions