I've got a bit of a problem with a web site i've been working on. I can't seem to get the php script to insert all the data into the database. I'm sending a byte array from flash to a php script to insert into a data base, and though it inserts it, it only inserts part of it. I dunno if the data is getting corrupted or the data just isn't being inserted all the way (when retrieving the photo comes out half grey). I've written a script in java to do the same thing and it works perfectly (I haven't had much experience in php). here's the php script...
Code: Select all
$query = $link->prepare("UPDATE PHOTO SET PHOTO_DATA=? WHERE PHOTO_ID='".$id."'");
$query->bind_param('s', $photo);
$data = fopen("php://input", 'r');
while(!feof($data)){
$query->send_long_data(0, fread($data, 8192));
}
fclose($data);
if (!$query->execute())
die("Unable to query" . mysql_error());
Code: Select all
...
var fdataRequest:URLRequest = new URLRequest(insertUrl);
var fdataLoader:URLLoader = new URLLoader();
fdataRequest.contentType = 'application/octet-stream';
fdataRequest.method = URLRequestMethod.POST;;
fdataRequest.data = photo.picture;
fdataLoader.addEventListener(Event.COMPLETE, fdataChannelComplete);
fdataLoader.addEventListener(IOErrorEvent.IO_ERROR, ioError);
fdataLoader.load(fdataRequest);
...
...
private function fdataChannelComplete(e:Event):void{
//e.target.removeEventListener(Event.COMPLETE, fdataChannelComplete);
var response:String = e.target.data;
if(response == 'success'){
var evt:NetworkEvent = new NetworkEvent(NetworkEvent.PHOTO_DATA_INSERT_COMPLETE);
this.dispatchEvent(evt);
} else {
Alert.show("Não foi possivel communicar com o servidor\n ERROR:::"+response);
}
}