转换网址中的网址错误导致错误

时间:2016-03-22 09:12:19

标签: php android android-volley slim

嘿,我有这样的代码将url目录保存到数据库并将文件传输到目录

   $app->post('/gambar', function() use($app) {
            // check for required params


        verifyRequiredParams(array('directory'));

        if (isset($_FILES['image'])) {
            if(isset($_POST['directory'])){
                $directory = $app->request->post('directory');
                $full_directory_path = '../' . $directory;

                //Pengecekan folder, sudah tersedia atau belum
                if(!is_dir($full_directory_path)){

                    //Pembuatan folder baru
                    mkdir($full_directory_path, 0777, true);
                }
                //Menentukan tempat file akan disimpan
                $target_path = $full_directory_path . '/' . basename($_FILES['image']['name']);
                if (!move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {

                    //File gagal dipindahkan ke server, biasanya karena folder yang dituju tidak tersedia
                    $response['kode'] = 1;
                    $response['pesan'] = "File tidak dapat dipindahkan ke server";
                    echo json_encode($response);
                }else{
                    // File berhasil diupload
                    $response['kode'] = 2;
                    $response['gili'] = $target_path;
                    $response['pesan'] = "File berhasil diupload";
                    echo json_encode($response);
                }
            }else{

            }
        } else {

            //Jika file tidak terkirim dari android
            $response['kode'] = 0;
            $response['pesan'] = 'File tidak terkirim ke server';
            echo json_encode($response);
        }
        $user_id = 1;           
        // $gambar = $app->request->put('gambar');


        $db = new DbHandler();
        $res = array();

        // updating task
        $result = $db->updateGambar($target_path,$user_id);
        if ($result) {
            // task updated successfully
            $res["error"] = false;
            $res["message"] = "Task updated successfully";
        } else {
            // task failed to update
            $res["error"] = true;
            $res["message"] = "Task failed to update. Please try again!";
        }
        echoRespnse(200, $res);

    });

我希望更改为此,以便保存完整的网址,而不仅仅是这个'../'

$full_directory_path = 'http://192.168.0.13/task_manager/' . $directory;

但是当我用完整的url更改它时,它会让我在volley android中出错。任何人都知道这段代码有什么不对吗?

日志中的错误只是这个

03-22 16:01:37.148 32391-19996/com.anakacara.anakacara E/Volley: [773] BasicNetwork.performRequest: Unexpected response code 500 for http://192.168.0.13/task_manager/v1/gambar

1 个答案:

答案 0 :(得分:1)

如果您想更改网址,为什么不创建新变量:

$example = 'http://192.168.0.13/task_manager/'.$directory. '/' . basename($_FILES['image']['name']);

并将此变量发送到您的数据库。

我猜你的排球需要'../'这个代码才能正常工作,所以它会给你500个错误