最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Get image URL after image created from canvas and sent to WP uploads with AJAX

programmeradmin0浏览0评论

Hello there people my people, sorry I'm a PHP newbie and could use some help!

I'm making an image from a canvas element which is being converted from BASE64 into a .PNG and sent to my WP uploads folder using AJAX and the following function in my functions.php:

function canvasUpload(){
    $uploads = wp_upload_dir();
    $img = $_POST['uploadImage'];
    $img = str_replace('data:image/png;base64,', '', $img);
    $img = str_replace(' ', '+', $img);
    $data = base64_decode($img);
    $file = $uploads['path'].'/'. uniqid() . '.png';
    return; 
    $r = file_put_contents($file, $data);
    echo $r ? $file : 'Error saving file';
}

//AJAX CALL
$.ajax( {
    type: "POST",
    url: ajaxurl,
    data: {
        action: 'canvasUpload',
        uploadImage: data
    }
} ).done(function(o) {

});
});
});

I need to be able to get the URL of the image in my uploads folder after it's created, so I can use it in my template and access with Javascript. I'm assuming this is created from the $file variable, but I don't know how to echo it in my template.

Any help much appreciated!

发布评论

评论列表(0)

  1. 暂无评论