duan1982453 2016-06-05 06:24
浏览 75
已采纳

将Base64编码的图像上载到PHP服务器

I'm trying to upload a Base64 encoded .Png file to a PHP server from an Android application.

Below code doesn't return anything in the response. What am I doing wrong?

I'm sending the Base64 encoded string and the name of the file. (ex:"sign1234.png")

<?php

if(isset($_POST['image']) && isset($_POST['name']){

$image = $_POST['image'];
$name = $_POST['name'];

$png = base64_to_jpeg($image,$name);

$target = 'uploads/'.$name;
$result = move_uploaded_file( $_FILES['$png']['tmp_name'], $target);

if($result){
        $response["success"] = 1;
        $response["message"] = "Upload Successful.";
        echo json_encode($response);
}else{
    $response["success"] = 0;
    $response["message"] = "Server error. Could not upload.";
    echo json_encode($response);
}

}

function base64_to_jpeg($base64_string, $output_file) {
    $ifp = fopen($output_file, "wb"); 

$data = explode(',', $base64_string);

fwrite($ifp, base64_decode($data[1])); 
fclose($ifp); 

return $output_file; 
}
?>
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 苹果手机删除了qq软件,qq文件怎么恢复
      • ¥20 用mips 人力编程排序问题(能在mars按要求运行)
      • ¥15 Verilog小型神经网络(单层反馈神经网络)
      • ¥15 设计一个数字钟,实现时分秒的显示
      • ¥15 Clion使用头文件链接两个cpp
      • ¥15 51单片机无法触发外部中断问题
      • ¥15 基于半监督,无监督的调制识别
      • ¥15 cst求 阵列 rcs 时候 频域 时域求解器 应该怎样设置 才让两者 计算结果 相似 请附图
      • ¥15 关于#51单片机#的问题:大家帮我看一下为什么我的计时器数字一直不稳定
      • ¥15 Qt 在应用程序里总是有[PREVIEW] recv window msg, name:(Qt5QWindowIcon) hwd:(287097a)等信息不断输出,怎么解决