# Unable to save image to database! HELP please T\_T

**URL:** <https://forum.kirupa.com/t/unable-to-save-image-to-database-help-please-t-t/311868>\
**Category:** Uncategorized\
**Created:** [July 19, 2010, 7:30am UTC](https://forum.kirupa.com/t/unable-to-save-image-to-database-help-please-t-t/311868 "2010-07-19T07:30:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![YenXz](https://avatars.discourse-cdn.com/v4/letter/y/eb9ed0/32.png) [@YenXz](https://forum.kirupa.com/u/YenXz)\
**Post date:** [July 19, 2010, 7:30am UTC](https://forum.kirupa.com/t/unable-to-save-image-to-database-help-please-t-t/311868/1 "2010-07-19T07:30:13Z")

</div>

Hey guys, i am having problem uploading a byte array to my database. I am new here… Please help me :pirate:

thanks in advance!  
this is my codes.

```auto
var ba:ByteArray = PNGEncoder.encode(bmd);
					
					
					var _request:URLRequest = new URLRequest ("http://localhost/image/readimage.php");
					var loader: URLLoader = new URLLoader();
					_request.contentType = "application/octet-stream";
					_request.method = URLRequestMethod.POST;
					_request.data = ba;
					loader.load( _request );

```

and this is my php code

```auto
<?php
ini_set('display_errors', 1);
ini_set('log_errors', 0);
ini_set('error_reporting', E_ALL);

$username = "root";
$password = "mysql";
$host = "localhost";
$database = "user";

// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

// Select your database
mysql_select_db ($database);

$fp = fopen("file.txt", "wb");
if(fwrite($fp,$GLOBALS["HTTP_RAW_POST_DATA"])) {
	echo "writing=Ok";
	
	
	
	$query ="INSERT INTO kc (pic) VALUES ('HTTP_RAW_POST_DATA')" or die(mysql_error());
	
 	$results = mysql_query($query, $link);
 }
else {echo "writing=Error";}

fclose($fp);

?>

      

```

i am able to upload some data, but its not the image of data. is more like some junk data.
