dongyang1518 2016-06-27 09:17
浏览 23

从PHP发送和映像到Javascript(JSON)

I'm trying to make a "meal" in my DB, so in my website i made a form with a name, and a picture. This is the code of the form :

<?php
        $new_meal_title = htmlentities($_POST["new_meal_title"]);
        $new_meal_img = htmlentities($_POST["new_meal_img"]);

        $data = array(
            'new_meal_title' => $new_meal_title,
            'new_meal_img' => base64_encode($new_meal_img)
        );

        $options = array(
            'http' => array(
                'header'  => "Content-type: application/x-www-form-urlencoded
",
                'method'  => 'POST',
                'content' => http_build_query($data)
            )
        );

        $context = stream_context_create($options);
        $result = file_get_contents(constant("API_URL")."/meal", false, $context);
        if($result === FALSE){
            var_dump($result);
        }

        $json = json_decode($result);

        if($json->success == "true"){
            header('Location: ../../');
            return;
        }
        else{
            echo $json->message;
        }
        header('Location: ../../');
?>

The form is sending data to my Node API. My Question is, how to save into a folder the image path through form in Javascript after it has been received in JSON.

  • 写回答

1条回答 默认 最新

  • dqmg80654 2016-06-27 13:20
    关注

    Thanks for your help, i just had to change this line :

    $new_meal_img = htmlentities($_POST["new_meal_img"]);
    

    By

    $new_meal_img = $_FILES['new_meal_img']["tmp_name"];
    

    And

    'new_meal_img' => base64_encode($new_meal_img)
    

    By

    'new_meal_img' => base64_encode(file_get_contents($new_meal_img))
    
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效