C# 利用 WebClient 上傳 檔案 到PHP的程式中
C# 利用 WebClient 上傳 檔案 到PHP的程式中
資料來源:http://stackoverflow.com/questions/10237983/upload-to-php-server-from-c-sharp-client-application
class UploadFile2PHP { /* <?php $uploads_dir = ‘./files’; //Directory to save the file that comes from client application. if ($_FILES[“file”][“error”] == UPLOAD_ERR_OK) { $tmp_name = $_FILES[“file”][“tmp_name”]; $name = $_FILES[“file”][“name”]; move_uploaded_file($tmp_name, “$uploads_dir/$name”); } ?> */ static public void UploadFile(String StrUrl,String StrFilePath) {//http://stackoverflow.com/questions/10237983/upload-to-php-server-from-c-sharp-client-application WebClient Client = new System.Net.WebClient(); Client.Headers.Add(“Content-Type”, “binary/octet-stream”); byte[] result = Client.UploadFile(StrUrl, “POST”,StrFilePath); string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length); } } |