这是我的第一篇Stack Overflow帖子,如果我使用了不正确的格式或约定,请原谅我.我正在尝试编写一个测试场景,它从网页POST(multipart / form-data)接收png图像,剥离已发布的图像并将其作为Content-Type:image / png转发给第三方.
我有一个php文件(catcher.php),它是转发图像的收件人. Post.php,将上传的图像发布到catcher.php的php文件如下:
$img = imagecreatefrompng($_FILES['myfile']['tmp_name']);
imagepng($img);
$opts = array(
'http'=>array(
'method'=>"POST",
'content'=>$img,
'header'=>"Content-Type: image/png\r\n"
)
);
$context = stream_context_create($opts);
file_get_contents( "http://localhost/catcher.php", false, $context);
?>
Post.php从发布为multipart / form-data的网页上获取文件很好,但是我不确定如何访问catcher.php中的image / png内容.
我的问题是,在catcher.php中,我如何访问图像内容?我尝试过$_POST [‘content’]并获得以下错误:“Undefined index:content”.所以我知道我不是在寻找正确的数据.是否有一个特定的超全局变量,如$_POST或$_REQUEST,我可以使用它来访问已发布的图像内容,还是有其他解决方案?
解析度
我能够使用以下catcher.php代码找到我要查找的结果:
$input = fopen("php://input","+r");
$destination = fopen($target_path, 'w');
stream_copy_to_stream($input, $destination);
fclose($input);
fclose($destination);
?>
感谢Marc和Brenden的快速回复!