【发布时间】:2022-01-11 10:25:31
【问题描述】:
我正在使用 Laravel HTTP 客户端将数据发送到练习 PHP API。我的 Laravel 代码:
$p = 'img.jpg';
$path = storage_path('app' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $p);
$response = Http::attach('new_file', file_get_contents($path), 'new_file.jpg')->post('http://localhost/imageresizer/service.php',
['sizes[0][new_width]' => 400, 'sizes[0][new_height]' => 200, 'sizes[1][new_width]' => 300, 'sizes[1][new_height]' => 500]);
$json = json_decode($response);
dd($json);
我的 php 脚本中有这个:
$response = [
'status' => http_response_code(),
'zip name' => basename($zipname),
'link' => 'http://localhost/imageresizer/zip/' . basename($zipname)
];
header("Content-Type: application/json");
echo json_encode($response);
我想从我的 PHP API 中的 $response 键访问每个值,但我失败了。我该怎么做? (dd($json); 的当前结果为空)。我想在我的 Laravel 应用程序中执行 $json->$response['status']; 之类的操作。
【问题讨论】: