[英]Upload image to Web using C# Xamarin Android
我想使用POST上傳圖像,但是在上傳文件時總是顯示錯誤(“上傳文件時出錯,請重試”)。 當我回顯$link
,僅顯示“ uploaded //”。
如何在C#代碼中的$_FILES["file"]
中重命名“ file”變量?
variabel uriFotoAndr.Path返回:
/storage/sdcard1/DCIM/Camera/MYIMAGE.jpg
C#代碼:
System.Net.WebClient Client = new System.Net.WebClient();
Client.Headers.Add("Content-Type", "binary/octet-stream");
byte[] result = Client.UploadFile("my.web.com/ppl/post_image.php", "POST", uriFotoAndr.Path);
string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);
Toast.MakeText(this, s, ToastLength.Long).Show();
PHP代碼:
<?php
$uploads_dir = 'uploaded/';
if ($_FILES["file"]["error"] == UPLOAD_ERR_OK)
{
$tmp_name = $_FILES["file"]["tmp_name"];
$name = $_FILES["file"]["name"];
$link= $uploads_dir."/".$name;
if( move_uploaded_file($tmp_name, $link))
{
echo "Success: Picture Upload Successfully!";
}
else
{
echo "There was an error uploading the file, please try again!".$link;
}
}
else
{
echo "Error: Picture not Uploaded";
}
?>
我正在使用VS 2015和Xamarin構建此應用程序。 提前致謝...
我已經找到答案了
我在C#代碼上的網絡鏈接之前:
然后我在鏈接中添加“ www”:
我可以上傳!!! :D
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.