如何在asp.net(FileUploadControl)中仅上传图像,不仅要进行扩展名验证,因为我在用.jpg / .png更改任何文件上传的扩展名时发现了它。
Here's a prototype code that you can use
if (FileUpload1.HasFile)
{
string extension = System.IO.Path.GetExtension(FileUpload1.FileName);
if (extension == ".jpg")
{
FileUpload1.SaveAs("yourpath" + FileUpload1.FileName);
}
else
{
Response.Write("Only .Jpg allowed");
}
}
You can add .PNG,.bmp also.. if u want
use ajax file upload..!! then save the file name in the database..!!
could get the extension "System.IO.Path.GetExtension(AsyncFileUpload1.PostedFile.FileName)"
refer this link..!!
http://www.aspsnippets.com/Articles/Using-ASP.Net-AJAX-Control-Toolkits-AsyncFileUpload-Control.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.