Lotus@ 2016-04-16 19:14 采纳率: 100%
浏览 29

在AJAX中将图像发布到PHP

I would like to send an image to a php file using AJAX.

Here's my JS code:

$.ajax({
    type: "POST",
    url: "http://website.com/add-image.php",
    data: "img=" + img
})

And That's my PHP

<?php
if ( !empty( $_POST["img"] ) )
{
    move_uploaded_file( $_POST["img"], "image.png" );
}
?>

but it doen't work.

I also tried to replace move_uploaded_file by imagepng or imagejpg but still no result.

How can I save the image on my server ? Thanks

  • 写回答

3条回答 默认 最新

  • weixin_33698823 2016-04-16 20:54
    关注

    If your sending your data using a post, The data property should be a json:

    $.ajax({
        type: "POST",
        url: "http://website.com/add-image.php",
        data: {img: img}
    })
    
    评论

报告相同问题?