convert PHP to asp.net

Last post 08-05-2009 11:58 PM by vnr8111. 6 replies.

Sort Posts:

  • convert PHP to asp.net

    03-11-2008, 3:32 PM
    • Member
      1 point Member
    • teodie
    • Member since 12-12-2006, 4:23 PM
    • Posts 7

     Hi,

    I want to convert the php code to asp.net if possible.

    see code below. thanks

     

    <?php

    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/jpeg');

    header("Content-Disposition: attachment; filename=".$_GET['name']);

    echo $im;

     

    } else echo 'An error occured.';

    ?>

  • Re: convert PHP to asp.net

    03-11-2008, 9:45 PM

    It is, but more stuff gets posted to a typical asp.net page than just one thing. I'm not sure the raw post data would be the same from Apache to IIS either. You would probably want to grab it by its name.

    What are you doing there, having something post a file to a page and then stream it to the browser? Was there a reason you're streaming raw bytes rather than just attaching a file? I have a typical file download stream script I can post here, but it takes a filename as a parameter and streams that file. 

    Please Mark As Answer posts that helped you.

    "If we learn from our mistakes, I should be brilliant by now."


    MCTS - .NET Framework 2.0: Web Applications
  • Re: convert PHP to asp.net

    03-12-2008, 11:55 AM
    • Member
      1 point Member
    • teodie
    • Member since 12-12-2006, 4:23 PM
    • Posts 7

    I have a flash app that saves the movie clip into an image. The flash is passing a http/POST  ByteArray to the php page.

    Im using the Context.Request.InputStream to get the ByteArray and convert to an Image but looks different when i convert the inputream to an image.

     

  • Re: convert PHP to asp.net

    11-07-2008, 2:31 PM
    • Member
      2 point Member
    • rsenna
    • Member since 11-07-2008, 7:28 PM
    • Sao Paulo, Brazil
    • Posts 1

    Funny, I've just made exactly the same code conversion. Then I found this thread, so I'm gonna share with you. Hope it helps.

     

     
    	public partial class JpgEncoderDownload : System.Web.UI.Page
    	{
    		protected void Page_Load(object sender, EventArgs e)
    		{
    			string filename = Request["name"];
    			if (string.IsNullOrEmpty(filename)) return;
    
    			var data = Request.BinaryRead(Request.TotalBytes);
    			Response.AddHeader("Content-Type", "image/jpeg");
    			Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
    			Response.OutputStream.Write(data, 0, data.Length);
    			Response.End();
    		}
    	}
    
     

     

  • Re: convert PHP to asp.net

    03-18-2009, 1:03 PM
    • Member
      2 point Member
    • maspevig
    • Member since 11-14-2005, 5:14 AM
    • Posts 1

    Awesome post, thanks rsenna... exactly what I was looking for, worked perfectly on the first try!

  • Re: convert PHP to asp.net

    05-05-2009, 11:45 PM
    • Member
      2 point Member
    • stephen007
    • Member since 05-06-2009, 3:39 AM
    • Posts 1

    I'm looking at the exact same flash example and am struggling to see any results.

    I'm using flash 10 which I understand may be preventing the save as dialog from displaying.

    I want to save the file to the filesystem using the ASP.NET script anyway, so the save as dialog isn't really an issue. But I'm not able to save a valid image. My data is only 29 bytes (Request.TotalBytes) which makes me question whether I'm outputting from Flash correctly in the first place. Here's my code.

    var data : ByteArray = ImageSnapshot.captureImage( myContainer, 0, new JPEGEncoder()  ).data;
    var params:Object = new Object();
    params.data = data;
    imgService.send(params);

    where imgService is:

    <mx:HTTPService id="imgService"
      url="http://localhost/Ajax/ImgService.aspx" result="imgServiceHandler(event)" method="POST" resultFormat="text">
    </mx:HTTPService>

    Thanks for any help!
    Stephen Howard

  • Re: convert PHP to asp.net

    08-05-2009, 11:58 PM
    • Member
      16 point Member
    • vnr8111
    • Member since 05-08-2009, 1:50 AM
    • Posts 8

    Hi,

    I need to convert below PHP to ASP.NET. Can any body help me in this regard

     

    <?php

    ini_set("include_path", ini_get('include_path').":/usr/lib/php/pear/share/

    pear");

    require_once 'HTTP/Request.php';

    function pac_register_user($screening_profile_id, $user_data) {

    $client_id = '__client_id__';

    $auth_key = '__client_web_service_auth_key__';

    $pac_url = '

    $r = new HTTP_Request($pac_url.'/services/reception_partners/

    register_user.xml?auth_key='.$auth_key.'&client_id='.$client_id,

    array('method' => HTTP_REQUEST_METHOD_POST));

    $r->addPostData('user_registration',array('screening_profile_id' =>

    $screening_profile_id, 'user_data' => $user_data));

    try {

    $r->sendRequest();

    $xml_data = $r->getResponseBody();

    echo '<pre><code>'.htmlspecialchars($xml_data).'</code></pre>';

    $xml_values = array();

    $parser = xml_parser_create('');

    if(!$parser)

    return false;

    xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');

    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);

    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);

    xml_parse_into_struct($parser, trim($xml_data), $xml_values);

    xml_parser_free($parser);

    echo '<hr><pre><code>';

    print_r($xml_values);

    echo '</code></pre>';

    } catch (HttpException $ex) {

    echo $ex;

    }

    }

    pac_register_user("_screening_profile_id_", array("last_name"=>"_last_name_",

    "phone_mobile"=>"_phone_mobile_", "address_country"=>"_Country",

    "first_name"=>"_first_name", "password"=>"test34", "email"=>"_email_"));

    ?>

    http://services:develws@staging.pacexam.com';

    Professional

Page 1 of 1 (7 items)