上传来自php://input

上传来自php://input,php,Php,我正试图上传一个从angular 8应用程序提交到php后端的图像。我尝试通过以下方式创建图像: $str =file_get_contents('php://input'); $ext = $_SERVER['HTTP_X_FILE_TYPE']; $e = explode("/",$ext); $ext = $e[1]; $filename = md5(time()).'.jpg'; $path = 'upload/'.$filename; file_put_contents($path,$

我正试图上传一个从angular 8应用程序提交到php后端的图像。我尝试通过以下方式创建图像:

$str =file_get_contents('php://input');
$ext = $_SERVER['HTTP_X_FILE_TYPE'];
$e = explode("/",$ext);
$ext = $e[1];
$filename = md5(time()).'.jpg';
$path = 'upload/'.$filename;
file_put_contents($path,$str);
图像已创建,但始终已损坏

以下是我发送的标题:

'Content-Type': 'text/plain; charset=UTF-8',
有什么想法吗?感谢来自文档的

/* PUT data comes in on the stdin stream */
$putdata = fopen("php://input", "r");

/* Open a file for writing */
$fp = fopen("myputfile.ext", "w");

/* Read the data 1 KB at a time
   and write to the file */
while ($data = fread($putdata, 1024))
  fwrite($fp, $data);

/* Close the streams */
fclose($fp);
fclose($putdata);
?>

因此,您可以将
ext
更改为您上载的扩展名。

谢谢您的回复;-)问题仍然是一样的,图像已损坏…我正在使用,因此我没有自己的代码这是我的请求头:内容长度:437694内容类型:多部分/表单数据;边界=-----WebKitFormBoundaryJlzcrWDWhi4zPAwC@LaurentB因此它不是
put
,您无法使用
php://input
您必须使用
$\u文件获取文件
@LaurentB您的wlc,您可以接受我的答案;):)