c# - Upload file image validation -


i have these codes validation before can upload image. when try upload different files video files , etc. still pushing through? missing here? here whole code behind. im not sure looking im sorry. its accepting try upload , uploads no image.

protected void page_load(object sender, eventargs e)     {         if (session["islandgasadminpm"] != null)         {             if (!ispostback)             {                 getcategories();                  addsubmitevent();             }             if (request.querystring["alert"] == "success")             {                 response.write("<script>alert('record saved successfully')</script>");             }         }         else         {             response.redirect("login.aspx");         }     }     private void addsubmitevent()     {         updatepanel updatepanel = page.master.findcontrol("adminupdatepanel") updatepanel;         updatepanelcontroltrigger trigger = new postbacktrigger();         trigger.controlid = btnsubmit.uniqueid;          updatepanel.triggers.add(trigger);     }     private void getcategories()     {         shoppingcart k = new shoppingcart();         datatable dt = k.getcategories();         if (dt.rows.count > 0)         {             ddlcategory.datavaluefield = "categoryid";             ddlcategory.datatextfield = "categoryname";             ddlcategory.datasource = dt;             ddlcategory.databind();         }     }      protected void dropdownlist1_selectedindexchanged(object sender, eventargs e)     {      }      protected void btnsubmit_click(object sender, eventargs e)     {         if (uploadproductphoto.postedfile != null)         {             saveproductphoto();              shoppingcart k = new shoppingcart()             {                 productname = txtproductname.text,                 productimage = "~/productimages/" + uploadproductphoto.filename,                 productprice = txtproductprice.text,                 productdescription = txtproductdescription.text,                 categoryid = convert.toint32(ddlcategory.selectedvalue),                 totalproducts = convert.toint32(txtproductquantity.text)             };             k.addnewproduct();             cleartext();             response.redirect("/admin/addnewproduct.aspx?alert=success");         }         else         {             response.write("<script>alert('please upload photo');</script>");         }     }     private void cleartext()     {         uploadproductphoto = null;         txtproductname.text = string.empty;         txtproductprice.text = string.empty;         txtproductdescription.text = string.empty;         txtproductquantity.text = string.empty;     }     private void saveproductphoto()     {         if (uploadproductphoto.postedfile != null)         {             string filename = uploadproductphoto.postedfile.filename.tostring();             string fileext = system.io.path.getextension(uploadproductphoto.filename);              //check filename length             if (filename.length > 96)             {                 response.write("image should not exceed 96 characters");             }             //check file type             else if (fileext != ".jpg" && fileext != ".jpeg" && fileext != ".png" && fileext != ".bmp")             {                 response.write("only jpg,jpeg,bmp , png allowed");             }             //check file size             else if (uploadproductphoto.postedfile.contentlength > 4000000)             {                 response.write("image should not exceed 4mb");             }             //save images folder             else             {                 uploadproductphoto.saveas(server.mappath("~/productimages/" + filename));             }         } 

you seem creating variable 'filename' , not using in next line when attempt extension. i'm not aware of detail of you're doing, that's immediate red flag me , might involved.

if can provide examples of value of 'filename' , 'uploadproductphoto.filename' i'll able work out what's going on.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -