I am writing a simple PHP file to upload a file on POST, and to also create a new image and include the path to that new image in the response.
For the JSON response I have set headers in the main PHP file that the POST is sent to - like so:
header("Content-Type: application/json");
Just before my JSON encoded echo this is.
Above that part I call a function from another PHP file that uploads the POST file, and one that is called after that rendering a different image using that uploaded file.
In that function in order to create the PNG file I need put on the disc I have to declare a new header right? Like so:
header("Content-type: image/png");
I then ofc get the doublet header problem.
How can I get around this problem?
I cannot use header_remove() BTW.
"In that function in order to create the PNG file I need put on the disc I have to declare a new header right?"
No.
Headers should only be sent to browsers. You don't need to send a header to write to disc.
In that function in order to create the PNG file I need put on the disc I have to declare a new header right?
You don't have to declare a new header. As Danack pointed out, headers are only used for sending information to the browser. For instance, if you want to output the binary data of that image and then call that header, it will render the image in the browser. For writing the image to disk, it's fairly simple.
<?php
move_uploaded_file($_FILES['image']['tmp_name'], 'Path/To/File/Location/'.$_FILES['image']['name']);
?>
And that should do it.