I’m trying to build a code framework for uploading, editing and downloading bitmap images. (You can see it at work here, though that version is a couple months old.) There’s a memory leak somewhere that’s been bugging me, so don’t use it for more than half an hour.
I’ve gotten the downloading code to work already– the BitmapData is encoded using Adobe’s PNG encoder class (it’s on code.google.com), the PNG data is sent to a PHP program, and then the PHP sends it as a file to the client again, which triggers a download.
But uploading is another story. So far I haven’t gotten anything to work– not only in the Actionscript sense, but also on the server. Code examples that work just fine on the site they’re hosted on aren’t working when I upload them straight to my server, and that suggests that the server needs to be properly configured in order for this to work.
Please paste in your PHP code! I’m being thwarted by HTTP_POST_RAW_DATA – and when I use $png = file_get_contents(“php://input”); I can download the file but am then told that it’s corrupt (or otherwise not a good PNG).
I’m confident that I’m using PNGEncoder the way it should be used; but my PHP script isn’t handling the raw stream correctly. Your help would be appreciated!
Alright, let’s see, I know it’s around here somewhere.
Try this:
<?php
// PHP code to save the picture to hard disk
// this code will open the download dialog-box window
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
// get bytearray
$im = $GLOBALS["HTTP_RAW_POST_DATA"];
// add headers for download dialog-box
header('Content-Type: image/'.$_GET['imgFormat']);
header("Content-Disposition: attachment; filename=".$_GET['name']);
echo $im;
} else echo 'An error occured.';
?>