我只是尝试使用php将图像发布到网址。我也使用ajax和jquery 任何人都可以帮助我解决问题。这是ajax和php代码片段。
$("#imgupload").click(function(){
var time = DateNow();
$.ajax({
type: "POST",
url: "<?php echo base_url()?>test/test_send_message",
contentType: false,
cache: false,
processData: false,
data: $("#imgfile").serialize(),
success: function(response){
console.log("time");
console.log(response);
},
error: function(){
console.log("error");
}
})
});
php code below
function test_send_message(){
//image upload
$tid = $_POST['tid'];
$mytpe = "img";
$image = $_POST['imgfile'];
$sid = $_POST['sid'];
$mytpe = "txt";
$message = $_POST['chatinput'];
$url = 'https://api.test.com/test/prod/v1';
$headers = array (
'Content-Type: application/json'
);