如何获取文件';在C#(windows窗体应用程序)中以数组形式显示的详细信息?
我想使用C#上传文件,我需要它的名称、类型和大小等,下面给出了一个例子。请让我知道,我该怎么做如何获取文件';在C#(windows窗体应用程序)中以数组形式显示的详细信息?,c#,php,arrays,image,C#,Php,Arrays,Image,我想使用C#上传文件,我需要它的名称、类型和大小等,下面给出了一个例子。请让我知道,我该怎么做 [file2] => Array ( [name] => MyFile.jpg [type] => image/jpeg [tmp_name] => /tmp/php/php6hst32 [error] => UPLOAD_ERR_OK
[file2] => Array
(
[name] => MyFile.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php/php6hst32
[error] => UPLOAD_ERR_OK
[size] => 98174
)
)
以下是我现有的代码:
private void choosFileBtn_Click(object sender, EventArgs e) {
OpenFileDialog ofdChoos = new OpenFileDialog();
if (ofdChoos.ShowDialog() == DialogResult.OK)
{
System.Net.WebClient Client = new System.Net.WebClient();
// Client.Headers.Add("Content-Type", "binary/octet-stream");
var sourceString = ofdChoos.FileName.Replace(@"\", @"/"); var source = @"" + sourceString;
var result = Client.UploadFile("https://zaffarology.com/upload.php", "POST", @source);
string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);
}
}
我自己解决了这个问题。感谢所有回复我并尽力帮助我的人。非常感谢 解决方案代码
OpenFileDialog ofdChoos = new OpenFileDialog();
if (ofdChoos.ShowDialog() == DialogResult.OK)
{
System.Net.WebClient Client = new System.Net.WebClient();
var sourceString = ofdChoos.FileName.Replace(@"\", @"/");
var source = @"" + sourceString;
string exts = Path.GetExtension(source);
string ext = exts.Replace(@".", string.Empty);
Client.Headers.Add("Content-Type", ext);
var result = Client.UploadFile("https://zff.com/upload.php", "POST", @source);
string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);
MessageBox.Show(s);
}
那代码看起来不像C#…你试过什么?你在哪里卡住了?你在谷歌上搜索了什么?那是PHP。你是想说你想从C#上传到php脚本吗?@Cory,是的,这是php,我需要C#中的相同内容。你提到的问题没有人回答,有两个重复标记(,),两个都接受了答案,至少看起来很有用。