douxie0824 2014-12-16 17:33
浏览 32

使用slim框架上传图像以及其他文本数据的REST服务

i been trying to make image uploading along with other text data and to put image in one folder that have to be reference with one id field of database.

i am using Slim framework for this rest api services. These are my codes

$app->post('/ProjectBook', function() use ($app) {
            verifyRequiredParams(array('flat_no', 'customer_name', 'status','photoid'));
            $response = array();
            $flat_no = $app->request->post("flat_no");
                        $customer_name = $app->request->post('customer_name');
                        $photoid = $app->request->post('photoid');
                        move_uploaded_file($_FILES["file"]["temp_name"], 'folders'.$photoid.'/'.$_FILES["file"]["name"]);
                        $data = array($flat_no,  $customer_name, $status, $photoid);   
            $db = getConnection();

                        $stmt = $db->prepare("INSERT INTO projectbook(flat_no, customer_name, status, photoid ) VALUES( ?, ?, ?, ?)");
            $res = $stmt->execute($data);
                            if ($res != NULL) {
                            $response["error"] = false;
                            $response["message"] = "submited successfully";

                             echoRespnse(201, $response);
                            } else {
                            $response["error"] = true;
                            $response["message"] = "Failed to insert data. Please try again";
                            echoRespnse(200, $response);
                            }  

           });

And i am using curl to test it

$curl -X POST -F "photoid=@pic.php" -F "flat_no=4&customer_name=yes&status=booked" http://localhost/Api_service/ProjectBook

but it doesn't work. Return my validation api of {"error":true,"message":"Required field(s) customer_name, status, photoid is missing or empty...."}

How can i perform this process?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)