0

我想从上传图片的地方获取图片的路径...

例如:我的图像在 E:drive 和图像文件夹中,我想在上传图像之前获取该路径

我的控制器代码如下

    public ActionResult UploadImage(UploadImageModel model)
    {

        if (ModelState.IsValid)
        {

            Bitmap original = null;
            var name = "newimagefile";
            var errorField = string.Empty;

            if (model.IsUrl)
            {
                errorField = "Url";
                name = GetUrlFileName(model.Url);
                original = GetImageFromUrl(model.Url);
            }
            else if (model.IsFlickr)
            {
                errorField = "Flickr";
                name = GetUrlFileName(model.Flickr);
                original = GetImageFromUrl(model.Flickr);
            }
            else if (model.File != null) 
            {

                errorField = "File";
                name = Path.GetFileNameWithoutExtension(model.File.FileName);
                original = Bitmap.FromStream(model.File.InputStream) as Bitmap;
            }


            if (original != null)
            {
                var img = CreateImage(original, model.X, model.Y, model.Width, model.Height);


                var fn = Server.MapPath("~/Content/img/" + name + ".png");
                img.Save(fn, System.Drawing.Imaging.ImageFormat.Png);


                return RedirectToAction("Index");
            }
            else 
                ModelState.AddModelError(errorField, "Your upload did not seem valid. Please try again using only correct images!");
        }

        return View(model);
    }
4

1 回答 1

1

it is not possible . it is a security threat if the browser sends the full path from client side.

于 2012-09-20T11:52:23.110 回答