An example of an advertisement carousel system (including the file upload method)

Source: Internet
Author: User
Online advertising has become a hot topic on the Internet. The 468x60 has become the size of the ad staff's brains. When processing an advertisement, if you can directly use the browser to send the 468x60 image file of the advertisement to the server that processes the advertisement, trust is a very comfortable Web advertisement and becomes a hot topic on the Internet. The size of 468x60 becomes the size of the ad staff's brains.
When processing an advertisement, if you can directly use a browser to send 468x60 of the advertisement image files to the server that processes the advertisement, trust is a pleasure and you do not need to open an FTP program, it takes up to half a day only for upload.

This title is the pain of all Web CGI programs, including ASP, Prel... and so on, all need to be achieved through the addition of system components. PHP is the most powerful Web CGI program. it is not disappointing in this aspect, or even proud of other CGI tools.

The File Upload function is described in the RFC 1867 File by using the special File structure (content-type) multipart/form-data. It is worth noting that the browser must use Netscape 3.0 or a version later than MS Internet Explorer 4.0 to upload files.

First look at the following HTML original code





In the form label, you need to participate in the enctype = 'multipart/form-data' string, which indicates that the materials input by the application have files to upload, and the method must use POST instead of GET.

In the above code, if the application name is filled in Wilson Peng and c: \ myphoto.gif file is selected, after the application presses the send key, the browser sends the following POST material.


Content-type: multipart/form-data, boundary = AaB03x

-- AaB03x
Content-disposition: form-data; name = 'user'

Wilson Peng
-- AaB03x
Content-disposition: form-data; name = 'myfile'
Content-type: multipart/mixed, boundary = BbC04y

-- BbC04y
Content-disposition: attachment; filename='myphoto.gif'
Content-type: image/gif
Content-Transfer-Encoding: binary

...Myphoto.gif content...
-- BbC04y --
-- AaB03x --


In the above materials, boundary = AaB03x is the message that leaves the materials in different columns. the AaB03x encoding method varies depending on the browser version, which is usually generated by the browser. Then you can
We can see that different columns are separated by -- AaB03x.

For example, the action program next. php for processing form automatically generates four variables, as shown in the following table.

Variable name clarification
$ Myfile: the uploaded file content
$ Myfile_name the name of the user who uploads the file
$ Myfile_size size of the uploaded file
$ Myfile_type specifies the file upload format, for example, 'image/GIF'


The most important action to do in the next. php program is to properly apply the four variables. otherwise, when the program ends, the files uploaded by the application will dissipate. Therefore, you need to copy $ myfile to the directory where the ad map is stored.

Copy ($ banner, '/home1/biglobe3/ad/'. $ banner_name );

This line of code stores the file in the/home/htdocs/ad directory. in the preceding example, the file is saved to/home/htdocs/ad/myphoto.gif. It is important that the stored directory cannot be the one that WebServer cannot read, but should be placed in the directory where the website's Homepage is located to be visible on the network.

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.