By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,116 Members | 1,319 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,116 IT Pros & Developers. It's quick & easy.

help converting php code to c#?

P: n/a
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.textamerica.com/recent.aspx";

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

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

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

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ch****@gmail.com wrote:
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.textamerica.com/recent.aspx";

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

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

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


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_contents($source_file);

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

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.