PHP image upload function, save in a dir and then return save image url

前端 未结 5 413
被撕碎了的回忆
被撕碎了的回忆 2021-01-03 12:55

I am trying to upload an image to server using PHP and the save inside a dir, and then returning the image url.

HTML:



        
5条回答
  •  北荒
    北荒 (楼主)
    2021-01-03 13:53

    Name :

    Code :

    Price :

    Image :

    "; print_r($_POST); print_r($_FILES);*/ $name = $_POST["name"]; $code = $_POST["code"]; $price = $_POST["price"]; $image = $_FILES["image"]["name"]; /* folder image save */ // $target_dir = "/var/www/html/shivam/new/upload/"; // $target_file = $target_dir.basename($_FILES["image"]["name"]); // /*echo "1121".$target_file;*/ // $name = basename($_FILES["image"]["name"]); // mysqli_query($con,$qry); // /* move file */ // move_uploaded_file($_FILES['image']['tmp_name'],$target_dir.$name); /* move_uploaded_file($tmp_name, "$target_dir/$name");*/ /* end */ $uploaddir = '/var/www/html/uploads/'; $uploadfile = $uploaddir . basename($_FILES['image']['name']); echo '44'.$uploadfile; echo "

    "; if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Upload failed"; } echo "

    "; echo '
    ';
    echo 'Here is some more debugging info:';enter code here
    print_r($_FILES);
    print "
    "; } ?>

提交回复
热议问题