Using PHP to implement AD carousel

Source: Internet
Author: User



Internet advertising has become a popular learning on the internet. And 468x60 became the size of the advertiser's brains.
In the process of advertising, if you can directly use the browser to the 468x60 map files to deal with ads in the server, I believe it is a very comfortable thing, do not have to open the FTP program, big Half-day only to upload.

This problem is the pain of all Web CGI programs, including ASP, Prel ... Double margin for the elderly and so on, all need to be increased through the system components to achieve. The most powerful Web CGI program: PHP, in this respect, did not disappoint, or even disdain for other CGI tools.

The file Upload feature is described in detail in RFC 1867 files, using a special file format (content-type) multipart/form-data. It is worth noting that browsers must use more than 3.0 of Netscape or MS Internet Explorer more than 4.0 version to upload files.

First look at the following HTML source code


< form enctype= "Multipart/form-data" action= "next.php" Method=post >
Your name: < input type=text Name=user >< br >
File name: < input name= "myfile" type= "file" >< br >
< input type= "submit" value= "Send Out" >
</form >

In the form label, to join the enctype= "Multipart/form-data" string, indicating that the user input data on the file upload, and method must use POST and can not use get.

In the above code, if the user's name is filled in the Wilson Peng, and select the C:myphoto.gif file, the user presses the send out key, the browser will send the following post data. Install satellite TV


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 slightly ...
--bbc04y--
--aab03x--


In the above, boundary=aab03x is a message that separates different field data, where the aab03x encoding method varies depending on the browser's version, usually generated by a browser hash. After lighting works, you can see the--aab03x to separate the fields.

For example, the action program to handle the form next.php, will actively generate four variables, see the following table

Description of variable name
$myfile the contents of the file uploaded
$myfile _name The name of the uploaded file on the user side
The size of the file uploaded $myfile _size
$myfile _type upload file format, such as "Image/gif"


In the next.php program to do the most important action is to use these four variables, or the end of the program, the user uploaded files disappeared. Therefore, first copy the $myfile to the directory where the advertisement is stored. Maotai

Copy ($banner, "/home1/biglobe3/ad/". $banner _name);

This line of procedure is to put the file in the/home/htdocs/ad directory, in the above example, to save the file to/home/htdocs/ad/myphoto.gif. The important thing is that the directory you are hosting cannot be a directory that Web Server cannot read, but should be placed in the homepage directory of your site before you can see it on the web.

Perhaps the program needs to be handled more detail, for example, than the size of the file obtained and the system return. Wait, we can use $myfile _size variables.

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.