Home > front end >  Image upload saved (2)
Image upload saved (2)

Time:12-03

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Results view:
Database: folder:

1. The first to send a post request to the controller
(1) to create a variable for the user to select image files

(2) build FormData data:
Var form=new FormData ();
Form. Append (" userPicture, "userPicture);
(3) use the JQuery Ajax send FormData data
Note: the file upload can only be used when the post submission, cannot be submitted using the get
Open the load layer: var layerIndex=layer. The load ();

2. The controller receives the parameter

Note: HttpPostedFileBase: on the base class for a class of these classes provide access to the client already upload individual files,

3. Save the avatars
(1) check whether there is a store user avatar directory

Note: the Exists: to determine whether a given path reference existing directory on the disk, the parameters of the reference is the path it to test, if the parameter referencing an existing directory, it is true; Otherwise it is false,
CreateDirectory: in the specified path creates all directories and subdirectories, returns an object, it said specified path corresponding directory,

(2) to determine whether to upload the picture

(3) the expansion of the file name

Note: GetExtension: the specified path string extensions,
(4) joining together to save the file name (in order to ensure the uniqueness of image file name, the convenient user use)
Note: the Guid: it means the globally unique identifier (Guid),
(5) joining together the path of the file

(6)
save uploaded files to the hard disk
Note: SaveAs: rewrite in the derived class, save to upload files, the content of the
(7) to save the file name to the user object, through the user object saved to the database



Conclusion: to save save pictures in userPicture folder, the names of the images stored in the database, so that you can through the database to find the picture name, find the corresponding image url path, through the SRC matching corresponding to the path of the img tags, make the image displayed on the page,
  • Related