代码之家  ›  专栏  ›  技术社区  ›  Brian Hicks

相当于c中的$\u文件#

  •  2
  • Brian Hicks  · 技术社区  · 14 年前

    在C中,php的$_文件变量的等效值是多少?或者至少是以同样的方式访问文件的东西。我有一个上传表单,我无法更改,需要了解如何获取这些文件。

    3 回复  |  直到 12 年前
        1
  •  9
  •   Rob    14 年前

    看一看 Request.Files 例如:

    foreach (HttpPostedFile item in Request.Files)
    {
        var filename = item.FileName;
    
        var fileBytes = new byte[item.ContentLength];
        item.InputStream.Read(fileBytes, 0, item.ContentLength);
    
        // fileBytes now contains the content of the file
        // filename contains the name of the file
    }
    
        2
  •  2
  •   Timwi    14 年前

    你会有一个 HttpRequest 对象传入处理程序,对吗?只需访问该对象 Files 财产:

    for (int i = 0; i < request.Files.Count; i++)
    {
        var file = request.Files[i];
        // Do something with this file, for example:
        file.SaveAs(Path.Combine(someDirectory, file.FileName));
    }
    
        3
  •  0
  •   danpop    12 年前

    有时也可以使用httppostedfilebase参数(例如uploadify):

    前任:

    public ActionResult UploadPicture(HttpPostedFileBase fileData){
      img = Image.FromStream(fileData.InputStream, true, true);
    }