public string file_upload(FileUpload fileupload)
{
string msg = "-1";
if (fileupload.HasFile)
{
string fileextenion = Path.GetExtension(fileupload.FileName);
if (fileextenion.ToLower() != ".png" && fileextenion.ToLower() != ".jpg")
{
Response.Write("<script>alert('Only images are allowed to upload , please select jpg or png image.... '); </script> ");
}
else
{
int filesize = fileupload.PostedFile.ContentLength;
if (filesize > 2097152) //cannot upload > 2 mb image......
{
Response.Write("<script>alert('Only images are allowed to upload that are size of less than 2 MB '); </script> ");
}
else
{
Random r = new Random();
int r1 = r.Next();
int r2 = r.Next();
msg = "~/Content/Uploads/" + r1 + r2 + fileupload.FileName;
fileupload.SaveAs(Server.MapPath(msg));
}
}
}
else
{
Response.Write("<script>alert('please select a file '); </script> ");
}
return msg;
}
No comments:
Post a Comment