This is my first post for, so please forgive me if I used the wrong formatting or conventions. I am trying to write a test script that receives a png image from a POST web page (multipart / form-data), cuts out the image that was sent, and forwards it to a third party as Content-Type: image / png.
I have a php file (catcher.php) that is the recipient of the forwarded image. Post.php, the php file that sends the uploaded image to catcher.php is located below:
<?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 retrieves the file as accurately as possible from the web page, which places it as multipart / form-data, however I'm not sure how to access the contents of image / png in catcher.php.
My question is: in catcher.php, how do I access the contents of the image? I tried $ _POST ['content'] and I get the following error: "Undefined index: content". Therefore, I know that I'm just not looking for the right data. Is there a special supergroup variable like $ _POST or $ _REQUEST that I can use to access the hosted image content, or is there some other solution?
Solution I managed to find the result I was looking for, with the following code for catcher.php:
$input = fopen("php://input","+r"); $destination = fopen($target_path, 'w'); stream_copy_to_stream($input, $destination); fclose($input); fclose($destination); ?>
Thanks to both Mark and Brendan for your helpful answers!