I have problem with my file uploading. If I select multiple files, only a single file gets stored in the folder. Suppose I have selected 3 different files in one - then only the first file gets stored three times.
private void galleryImagesFunction()
{
try {
foreach (HttpPostedFile postedfile in galleryUpload.PostedFiles) {
System.IO.FileInfo file = new System.IO.FileInfo(galleryUpload.PostedFile.FileName);
string newname = file.Name.Remove((file.Name.Length - file.Extension.Length));
newname = (prodID.Text + "_" + newname + System.DateTime.Now.ToString("_ddMMyyhhmmss")) + file.Extension;
postedfile.SaveAs(Server.MapPath("/images/products/") + newname);
string filepath = Convert.ToString("/images/products/") + newname;
MySqlConnection con2 = new MySqlConnection();
con2.ConnectionString = ConfigurationManager.ConnectionStrings("conio").ConnectionString();
string query = "INSERT into table (`image`, `productID`, `status`) values (@image, @productID, @status)";
MySqlCommand cmd2 = new MySqlCommand(query, con2);
con2.Open();
cmd2.Parameters.AddWithValue("@image", filepath);
cmd2.Parameters.AddWithValue("@productID", prodID.Text);
cmd2.Parameters.AddWithValue("@status", "active");
cmd2.ExecuteNonQuery();
con2.Close();
}
} catch (Exception ex) {
Response.Write(ex);
}
}
UPDATE (Form Code)
<asp:FileUpload ID="galleryUpload" runat="server" ClientIDMode="Static" CssClass="hiddenl" AllowMultiple="true" />
UPDATE (Web.config)
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5.2" />
<httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0"/>
<customErrors mode="Off"/>
<trust level="Full"/>
<pages validateRequest="false"></pages>
</system.web>