These days in the image upload and display, upload the picture to save the folder and save the path to the database, display with data binding display
Make this picture control the path where the patch is attached
Before the online collection of relevant information, most people say that this path should be an absolute path rather than a relative path, so the storage path is open to save this is the case
But the running result is ....
The avatar here can't be displayed.
Later, with the help of seniors, the storage path was modified to
This is a relative path, and the VS read data starts looking in this "meta-space" folder (that is, starting from the root directory), Subordinate folder Images Search 20161124213555917.jpg is successful, if the path like the beginning is not found, so display as blank
The following are the results of the normal operation:
Success!
Here is the relevant code to upload the image
1 if(Upload1. HasFile)//To determine whether a control has a file path2 {3 stringfilename = upload1. FileName;//Get file name4filename = filename. Substring (filename. LastIndexOf (".") +1);//get suffix5 if(filename. ToLower () = ="jpg"|| FileName. ToLower () = ="gif")//Judging Type6 {7 stringimg = DateTime.Now.ToString ("yyyymmddhhmmssfff") +"."+filename;8Upload1. SaveAs (Server.MapPath ("images/") +img);9 stringPicture = ("images/") +img;Ten //upload to the root directory of the images folder + renamed file name, you can also use the original picture name, self-determined. Upload success; One stringsql ="INSERT into tabusers values ('"+ ID +"', '"+ name +"', '"+ Hspwd +"', '"+ Sex +"', '"+ year+"', '"+mail+"', '"+ Question1 +"', '"+ Hsanswer +"', '"+ Picture +"')"; A intRESULT2 =class.put (SQL); - if(RESULT2 = =1) - Binddata (); the Else if(Result2! =1) - { -Response.Write ("<script>alert (' Registration failed! ');</script>"); - return; + } - } + Else A { atResponse.Write ("<script>alert (' image format only supports JPG and GIF ');</script>"); - return;//Prompt Error - } - } - Else - { inResponse.Write ("<script>alert (' Please choose photos! ');</script>"); - return;//Prompt Error to}
Look inside. "
String picture = ("images/") + img;
", Save the Path
The database stores the picture path and displays the picture