# Uploading files (AS3, PHP, config)

**URL:** https://forum.kirupa.com/t/uploading-files-as3-php-config/224103
**Category:** flash
**Created:** [April 28, 2007, 4:47pm UTC](https://forum.kirupa.com/t/uploading-files-as3-php-config/224103 "2007-04-28T16:47:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Rezmason](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rezmason/32/30447_2.png) [@Rezmason](https://forum.kirupa.com/u/Rezmason)
#### Post date: [April 28, 2007, 4:47pm UTC](https://forum.kirupa.com/t/uploading-files-as3-php-config/224103/1 "2007-04-28T16:47:11Z")

</div>

I’m trying to build a code framework for uploading, editing and downloading bitmap images. (You can see it at work [here](http://cgi2.cs.rpi.edu/~sachsj/toolset/), 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](http://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.

Any insight at all would be appreciated. 🙂

---

<div class="post-metadata">

### Author: ![drunkencop](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@drunkencop](https://forum.kirupa.com/u/drunkencop)
#### Post date: [June 17, 2008, 2:10pm UTC](https://forum.kirupa.com/t/uploading-files-as3-php-config/224103/2 "2008-06-17T14:10:59Z")

</div>

> [@Rezmason;2115409](#):
>
> 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](http://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.

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!

---

<div class="post-metadata">

### Author: ![Rezmason](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rezmason/32/30447_2.png) [@Rezmason](https://forum.kirupa.com/u/Rezmason)
#### Post date: [June 18, 2008, 2:50am UTC](https://forum.kirupa.com/t/uploading-files-as3-php-config/224103/3 "2008-06-18T02:50:55Z")

</div>

Alright, let’s see, I know it’s around here somewhere.

Try this:

```auto
<?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.';

?>

```
