Remember the process of public file processing after the separation of the website and front desk

Source: Internet
Author: User
Tags ftp file

Registered in the blog Park for several years, but has not developed the habit of blogging, garden age 2 years 3 months, no blog, no fans, little attention, but also basic weekly visit several times, supposedly also a wonderful super flood B, haha.

In the first half of the job, in the various interview process to find a job, only to find the importance of accumulation, a lot of problems in the past experience are more or less experienced, but most of them are a shallow, Baidu out of the answer, moving on the project with, can use, can't use to change and use, not to find other methods on the Internet. Always so, a few years down, the problem solved a lot, but think of those are their own will, really the network broke let me closed programming, I can write how many things, think on the frightened.

Not afraid of starting late, afraid of not moving, recently busy to do a website, two weeks of time to complete the site before and after the basic functions, time tight, task heavy, busy, in the process of practice in the encounter and solve one of the small problems, the process of settling down, the accumulation starts from here.

The problem is simple, the site is displayed in front of the foreground and backstage management. Backstage Management front desk data display, picture display and so on, after comparison, will backstage and the foreground separates, did two projects, the question is the backstage upload picture file, how in the foreground project displays.

Think of the use of ASP fileupload is can directly upload files to any physical path, think why not to save the uploaded files to a folder under the foreground project, for the front desk to read directly. Do what you say,

<Asp:fileuploadID= "FileUpload1"runat= "Server"BorderWidth= "1px"Width= "300px" /><Asp:buttonID= "Btnupload"runat= "Server"Text= "On the ¦ pass?"OnClick= "Btnupload_click" />
protected voidBtnupload_click (Objectsender, EventArgs e) {            if(Fileupload1.filename! =NULL&& FileUpload1.FileName.Length >0)            {                stringfname = DateTime.Now.ToString ("yymmddhhmmssfff") +Fileupload1.filename; //the article T on the ¦ pass ?                stringFullPath = Uploadfiles.load (FileUpload1,"images\\newsslider\\", fname); if(FullPath. Length >0) {MessageBox.Show ( This, FullPath,false); return; }                Else{FullPath="images/newsslider/"+fname; Imgqm.imageurl=""; Imgqm.imageurl=".. /"+FullPath; Imgqm.visible=true; }            }            Else{MessageBox.Show ( This,"File not selected",false); return; }        }

 Public Static stringLoad (FileUpload FileUpload,stringDirectorystringNewFileName) {         stringPath = HttpContext.Current.Request.PhysicalApplicationPath +newdirectory; stringpath2 = path. Replace ("Agriculturemanage","Agricultureplatform"); //¨¬ The ¨¦ of the examination of the records of the inspection, is it a .--------------------¨²,êcreatedirectory (path);         CreateDirectory (path2); Path= Path +filename; Path2= path2 +filename; //The sentence of " D" is ¨². No, no, no, no. In the case of the ¨, what is the deposit of the fruit? In the ¨², the ¨° to delete the ¦, except Y                if(file.exists (path)) file.delete (path); if(File.exists (path2)) File.delete (path2); //À¡ê Save a piece of paper TfileUpload.PostedFile.SaveAs (path); FileUpload.PostedFile.SaveAs (path2);}

Here the path and path2 are the background and the foreground folder path, so that the uploaded files in the background project and the front desk works are stored separately (background image used to display thumbnails, can not), at the same time, the foreground relative to the path into the DB, to this end of the work completed, the next is the front desk to show, Open the front desk project, you will find that the upload path already exists in the file just uploaded

Although these files are not included in the project, but through the is can be displayed, as long as the path in the DB, direct assignment, everything OK, deployed to IIS, test OK, background upload pictures, foreground refresh can show.

Summary, 1. This method has certain limitations, my front and back is deployed on the same server, so you can upload files, once deployed on different servers, non-project folder under the Read file, but also to discuss, it is said to use the folder mapping and FTP file server, which has learning materials and reference knowledge, Welcome to the Guide. 2. Due to file upload and database login synchronization, in the case of file upload failure, database write failure, the database rollback and file deletion processing must be noted, otherwise it may cause data and picture inconsistency problem.

The first time to write a blog, what is wrong, or there are other good ways to achieve, welcome to the discussion.

Remember the process of public file processing after the separation of the website and front desk

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.