Generate Response from Aspx page - php

I have a php page which hits an aspx page http://server/default.aspx?xml=abc , the file creates a PDF using xml sent in the query string and its stored on .net server.
Now, How can i get bytearray of PDF file thats generated??? I also want to know how to generate the response from aspx
Note: I am done till genrating bytearray in asp

It will open a file and write the binary response back to the caller.
using(var file = new FileStream("", FileMode.Open, FileAccess.Read))
{
var byteArray = new byte[file.Length];
var br = new BinaryReader(file);
byteArray = br.ReadBytes((int)file.Length);
Response.BinaryWrite(byteArray);
}

Related

Saving blob video with php

I am trying to send a buffered video to save it as a file on my server.
Always the file is empty.
My js get the url "blob:https://..." and sends to the php that receive it.
$file = file_get_contents(url);
file_put_contents($video_url_mp4."helloWorld.webm",$file);
I tried send the video as canvas and i only get one frame.
suggest please
A blob url is only usable in the browser that created it. So you cant use it on your server or copy and paste it into another browser or send the link to your friend etc.
What you need to do is get the blob that url was created from and use a FormData object and upload that to your server.
I get a file with the content as string on my php but this is not in a video format.
my js:
var myFile = new File(video.src);
var fd = new FormData();
fd.append('data', myFile);
and my php:
$f = $_POST['data'];
$decode = base64_decode(preg_replace('/^data\:image\/webp\;base64\,/', '', $f));
what is wrong?

How to export microphone recorded byearray as wav or mp3 from flash actionscript to php

I need help in exporting a bytearray to a wav or mp3 (or anything that runs!) from my flash code to my php page.
I am using microphone recorder to record voice, i use a a url request to send my ByteArray to my PHP page.
i send the bye array from flash like this:
var url = "http://localhost/wordswesay/uploads/testrec.php";
var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
var request:URLRequest = new URLRequest(url);
request.requestHeaders.push (header);
request.method = URLRequestMethod.POST;
request.data = soundBytes; //FLV byteArray
var loader:URLLoader = new URLLoader();
trace(request.data);
loader.load(request)
and in my php file, i do the following:
<?php
echo "test";
$im = $GLOBALS["HTTP_RAW_POST_DATA"];
$fp = fopen("test.wav", 'w');
fwrite($fp, $im);
fclose($fp);
?>
at the server side (the sime file as the php script) i get the test.wav with about 200kb of size but i can not play it! media players says it can't play this file as the codec might not be supported.
Any help would be appreciated
There is more to a audio file than the audio bytes, there needs to be a format specific header, and the bytes need to be stored in a way specific to the format type, which is often (mp3s for example) different then the raw bytes Flash will be giving you (which are decoded already)
Take a look on Google for a audio encoder, either in AS3 or PHP that will convert your bytes to a mp3 file, I'm sure there is something, but I don't know one off hand. Hopefully that explains why its not working, and pushes you into the right direction. Goodluck!

Saving bitmapdata to server and getting filename back?

Here's what I am trying to accomplish. I have a BitmapData that I am sending to a PHP function as ByteArray on the server by using URLRequest. The PHP function then saves the ByteArray as a jpg. All is well, so far and I am able to save the image on the server. Where I am stuck is that the PHP function generates the image file name randomly and I have no clue on how to get the name of the file I have just saved on the server. I am using the below code to send byteArray to the PHP function. How to modify/add this so I can get the filename of the image once it's saved on the server?
var myHeader:URLRequestHeader = new URLRequestHeader("Content-type","application/octet-stream");
var myReqst:URLRequest = new URLRequest(path);
myReqst.requestHeaders.push(myHeader);
myReqst.method = URLRequestMethod.POST;
myReqst.data = imageBytes;
var myLoader:URLLoader;
myLoader = new URLLoader();
myLoader.load(sendReq);
If you're using URLLoader (which I normally don't, HTTPService is better IMO), you can listen for the 'complete' even to the triggered, which you can then check the 'data' property on URLLoader for the filename returned by the php function (as long as php actually returns it).

How to send a FLV format data in byteArray using URLloader to a php script?

Im creating flash game that have the functionality to capture/record its gameplay that can be viewed later by the user, like a replay.
As for now Im already able to record the game and write it into a flv format in a ByteArray variable.
What Im working right now is how to send that ByteArray(the video file) to a php script and save it to a web server.
I've run into the URLLoader in flash where it can send the data and php will receive it thru the POST method. Unfortunately, the ByteArray containing the flv data must be first correclty encoded for php to read it. I figured this out from the example in the net where it does the same thing only that it is only sending a JPEG ByteArray instead of a FLV format using the JPEGENCODER.
Is there any existing class like the JpegEncoder for FLV format or any Video formats? Or any work around like creating the encoder my self?
Thanks in advance guys.
here is my current code to send the ByteArray
//send byteArray to a php script
var request:URLRequest = new URLRequest(url);
request.method = URLRequestMethod.POST;
//need to correctly encode first the ByteArray in FLV format
//....
request.data = fs; //FLV byteArray
var loader:URLLoader = new URLLoader();
trace(request.data);
Just figured this out.
I can now successfully send the flv byteArray in a php script where then the php receives it and save it as flv file in local system and uploading it in the youtube server using zend framework.
here's my code in flash.
//send byteArray to a php script
var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
var request:URLRequest = new URLRequest(url);
request.requestHeaders.push (header);
request.method = URLRequestMethod.POST;
request.data = fs; //FLV byteArray
var loader:URLLoader = new URLLoader();
trace(request.data);
loader.load(request)
and the scipt that receives and save it as a flv file:
$im = $GLOBALS["HTTP_RAW_POST_DATA"];
$fp = fopen("testVid.flv", 'w');
fwrite($fp, $im);
fclose($fp);
It turns out that I really dont need to encode the byteArray like what the JPEGEncoder is doing. Im still very new in flash and php though. And I have no idea if this is the best practice I can have. An advice would be greatly appreciated. Thanks guys.

How do I save a flex application snapshot to a file with PHP and then display it in the browser?

I'm trying to save a snapshot of a component in my flex app that is then sent to a php script to be saved and then spit back out into the browser window. I can't seem to get this to work.
Here's my FlashBuilder code:
private function saveImage():void {
var parameters:String = "snapshot=" + takeSnapshot(this);
var variables:URLVariables = new URLVariables(parameters);
var submit:URLRequest = new URLRequest("SaveImage.php");
submit.data = variables;
submit.method = URLRequestMethod.POST;
navigateToURL(submit,"_self");
}
private function takeSnapshot(component:IBitmapDrawable):String {
return ImageSnapshot.encodeImageAsBase64(ImageSnapshot.captureImage(component));
}
Here's my experimental PHP code:
$binaryData = base64_decode($_POST["snapshot"]);
$file = "mydirectory/tmp.png";
file_put_contents($file, $binaryData);
header("Content-type: image/png");
die($binaryData);
That generates the following output (where {path to image} is the url where the image was saved):
The image “{path to image}” cannot be
displayed, because it contains errors.
It does save a .png file to that directory but it's blank, there's nothing there but it's dimensions are correct. I've confirmed that the snapshot works by loading it in the app with a swfLoader component right after the snapshot is taken so I know the image is good before it's sent to the server.
Use the PNGEncoder instead.

Categories