I am converting a PHP file to C#,completed 75%,stuck with these lines
if(file_put_contents($uploaddir.$randomName, $decodedData)) {
//echo $randomName.":uploaded successfully"; //NO NEED TO CONVERT ECHO PART
}
PHP Brothers please help
MORE INFO
I converted this
// Encode it correctly
$encodedData = str_replace(' ','+',$data[1]);
$decodedData = base64_decode($encodedData);
to this
// Encode it correctly
string encodedData = data[1].Replace(' ', '+');
string decodedData = base64Decode(encodedData);
where base64Decode is
public static string base64Decode(string data)
{
byte[] binary = Convert.FromBase64String(data);
return Encoding.Default.GetString(binary);
}
Try this:
See the MSDN for details on the
WriteAllTextmethod.However, your approach of converting your data to a byte array, and then converting it to a string in the
base64Decodemethod, followed by writing it to the file is a bit too complicated IMO. You can just write your byte array to a file, decode the data like this:and then call
WriteAllBytes documentation here.