2012-09-20 93 views
0

我想從它被上傳在圖像的路徑...如何在上傳mvc之前獲取圖像源的路徑?

例如:我的形象是在E:驅動器和文件夾的圖片,我想我上傳的圖片之前得到這條道路

我Controllercode低於

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); 
    } 
+0

你可以使用Path.GetFullPath();方法 –

+0

我應該通過傳遞給GetFullPath();我試圖將它作爲字符串filepath = path.GetFullPath();? –

+0

你的意思是獲取客戶端的映像路徑嗎? – archil

回答

1

這是不可能的。如果瀏覽器從客戶端發送完整路徑,則會造成安全威脅。

+1

+1,簡單正確的答案。 –