Requesting help with one line of php to ASP.NET jpegcam from Google code

Last post 11-01-2009 2:17 AM by DaveCS2. 2 replies.

Sort Posts:

  • Requesting help with one line of php to ASP.NET jpegcam from Google code

    10-29-2009, 10:35 PM
    • Member
      4 point Member
    • DaveCS2
    • Member since 10-29-2009, 9:46 PM
    • Posts 4

    Hello all, I need a little help with a bit of php code to asp.net.

    Environment: VS2008
    Language: VB or C#

    Complete source: http://code.google.com/p/jpegcam/
    Specific file: test.php

    I have tried various logical asp.net (vb) variations to no avail.  In short, the project is flash based and allows the user to take a snapshot from their web-cam then upload the image to a web server.  Permissions, settings and testing proved successful with the php code as well as a sample asp.net upload and file creation.  The error is in my asp.net code.

    The php code is only a few lines long.  The line in question is below.

    $result = file_put_contents( $filename, file_get_contents('php://input') );

    Any help would greatly be appreciated. Thanks a million, Dave








    Entire php code:

    <?php
    $filename = date('YmdHis') . '.jpg';
    $result = file_put_contents( $filename, file_get_contents('php://input') );
    if (!$result) {
        print "ERROR: Failed to write data to $filename, check permissions\n";
        exit();
    }

    $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' . $filename;
    print "$url\n";

    ?>

    Filed under:
  • Re: Requesting help with one line of php to ASP.NET jpegcam from Google code

    10-30-2009, 4:38 AM
    • Member
      368 point Member
    • kdevendra
    • Member since 09-24-2008, 6:51 AM
    • Pune
    • Posts 79

    hi,

    function file-put-contents is used to write a string to a file. To know about it in more detail, check following link:

    http://php.net/manual/en/function.file-put-contents.php 

    function file_get_contents is used to write a string to a file. To know about it in more detail, check following link:

    http://www.php.net/manual/en/function.file-get-contents.php

    To convert the code from php to C#, refer this:

    http://www.csharp-station.com/HowTo/ReadWriteTextFile.aspx

    Regds,

    K. Devendra

    It's hard enough to find an error in your code when you're looking for it;
    It's even harder when you've assumed your code is error-free.

  • Re: Requesting help with one line of php to ASP.NET jpegcam from Google code

    11-01-2009, 2:17 AM
    Answer
    • Member
      4 point Member
    • DaveCS2
    • Member since 10-29-2009, 9:46 PM
    • Posts 4

    Thanks kdevendra.

    I have come up with a simple soultion that still needs error catching etc but works.

    My primary problem was the file_get_contents('php://input') section. I had to read the contents as  raw posted data in a stream.

    I came up with this and it finally worked.


     protected void Page_Load(object sender, EventArgs e)
        {
            string strFile = DateTime.Now.ToString("dd_MMM_yymmss") + ".jpg";
          FileStream log = new FileStream(Server.MapPath(strFile),
           FileMode.OpenOrCreate);
            byte[] buffer = new byte[1024];
            int c;
            while ((c = Request.InputStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                log.Write(buffer, 0, c);
            }
           //Write jpg filename to be picked up by regex and displayed on flash html page.
            Response.Write(strFile);
            log.Close();
    
        }


Page 1 of 1 (3 items)