help converting php code to c#?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chanko@gmail.com

    help converting php code to c#?

    hello all
    i don't know if this is the right place to put this but i need to
    convert the following code to c# - asp.net
    any help will be useful
    thnx in advance


    <?php
    //the web path of the image you want to get
    $source_file = "http://domain.textamer ica.com/recent.aspx";

    //the absolute file path you are writing to
    $destination_fi le = "/rootfolder/site/safeDirectory/pic0.jpg";

    //read the source file into buffer
    ob_start();
    readfile($sourc e_file);
    $filecontents = ob_get_contents ();
    ob_end_clean();

    //move its contents
    //this overwrites the destination file!
    if($fp = fopen($destinat ion_file,'w+')) {
    fwrite($fp,$fil econtents);
    fclose($fp);
    }
    ?>

  • Chris Hope

    #2
    Re: help converting php code to c#?

    chanko@gmail.co m wrote:
    [color=blue]
    > hello all
    > i don't know if this is the right place to put this but i need to
    > convert the following code to c# - asp.net
    > any help will be useful
    > thnx in advance
    >
    >
    > <?php
    > //the web path of the image you want to get
    > $source_file = "http://domain.textamer ica.com/recent.aspx";
    >
    > //the absolute file path you are writing to
    > $destination_fi le = "/rootfolder/site/safeDirectory/pic0.jpg";
    >
    > //read the source file into buffer
    > ob_start();
    > readfile($sourc e_file);
    > $filecontents = ob_get_contents ();
    > ob_end_clean();
    >
    > //move its contents
    > //this overwrites the destination file!
    > if($fp = fopen($destinat ion_file,'w+')) {
    > fwrite($fp,$fil econtents);
    > fclose($fp);
    > }
    > ?>[/color]

    Might be best to post this to a C# group and explain what the code does.

    I'm not quite sure in your code why you're buffering the output from
    readfile because you can either use fopen on the URL or you can simply
    do it with one line of code like so:

    $filecontents = file_get_conten ts($source_file );

    This will work whether it's a local file or a URL. (And from PHP5
    there's also the nice file_put_conten ts() function as well so you can
    write a file with one line of code).

    --
    Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

    Comment

    Working...