Hi,
Could anyone please help me with the following please?
If I have a jpg image on disk, it is easy to post it to a php script and save it server-side as follows:
C#
System.Net.WebClient Client = new System.Net.WebClient();
Client.Headers.Add("Content-Type", "binary/octet-stream");
byte[] result = Client.UploadFile("http://mywebsite.com/UploadImage.php", "POST", "PicData.jpg");
szResult = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);
and the PHP is as follows:
PHP
<?php
$uploaddir = "uploads/";
$szResult = "";
if (is_uploaded_file($_FILES["file"]["tmp_name"]))
{
$uploadfile = $uploaddir.basename($_FILES["file"]["name"]);
if (move_uploaded_file($_FILES["file"]["tmp_name"], $uploadfile))
{
$szResult = "Uuploaded successfully.";
}
else
{
$szResult = "Move to upload folder failed.";
}
}
else
{
$szResult = "Upload failed.";
}
echo $szResult;
?>
This all works great.
But, what if I have the jpg file in memory as a
byte[]
called
jpegAsByteArray
.
Well then I could do:
File.WriteAllBytes("PicData.jpg", jpegAsByteArray);
And call the above C# code and all will work fine.
But it seams wasteful to save it out to disk just to then send the bytes to the server using UploadFile.
How can I acheive the saving of the file on the server
WITHOUT also saving it on the client side?
Thanks,
Mitch.
[Edit]Code block added[/Edit]