Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony2.8。如何从post请求中获取数据_Php_Json_Symfony_Post_Save - Fatal编程技术网

Php Symfony2.8。如何从post请求中获取数据

Php Symfony2.8。如何从post请求中获取数据,php,json,symfony,post,save,Php,Json,Symfony,Post,Save,如何从控制器中的POST请求接收数据? 我不用树枝 public function newAction(Request $request) { //when I use $content = $request->getContent(); // as result I see "string" with need field and value. It's not json // array // value like /* string

如何从控制器中的POST请求接收数据? 我不用树枝

public function newAction(Request $request)
{
   //when I use
   $content = $request->getContent();
   // as result I see "string" with need field and value. It's not json
   // array
   // value like
   /* 
      string '------WebKitFormBoundaryI12ukQBs3HdmPjvh
      Content-Disposition: form-data; name="title"

      "valuefortitle"
      ------WebKitFormBoundaryI12ukQBs3HdmPjvh
      Content-Disposition: form-data; name="name"

      "supername"
      ------WebKitFormBoundaryI12ukQBs3HdmPjvh--
      ' (length=253)
      */
}
或者如何将Post数据序列化(转换)为对象或数组

我使用标题为“Content-Type:application/json”的邮递员发送请求


您能告诉我如何保存文件(图像)吗?

您可以用于POST请求:

$request->request->get('data');
对于获取请求:

$request->query->get('data');
对于文件查询:

$request->files.
并询问您的问题
如何保存图像?
,您必须创建
上传->卓越

$dir = $this->get('kernel')->getRootDir() . '/../web/uploads/images/';
$name = uniqid() . '.jpeg';

foreach ($request->files as $uploadedFile) {
    $uploadedFile->move($dir, $name);
}
$file = $this->get('kernel')->getRootDir() . "/../web/uploads/images/" . $name;

if (file_exists($file)) {
    echo "Successfully saved";
}

从请求中转储所有数据以查找可能的问题:
$request->request->all()

$request->request->get('content')

POST:
$request->request->get(“”)


获取:
$request->query->GET(“”)

结果我看到“空”。你能回答我的问题吗?我也面临类似的问题。这是我的问题