Home > Backend Development > PHP Tutorial > Implement advertising rotation using php

Implement advertising rotation using php

高洛峰
Release: 2023-03-02 20:44:02
Original
1863 people have browsed it

 Online advertising has become a hot topic on the Internet. And 468x60 has become a size that advertising staff are racking their brains for.
 When processing advertisements, it would be very comfortable if you could directly use the browser to send the 468x60 image file of the advertisement to the server that handles advertisements. You no longer need to open the FTP program and spend most of the day just to upload.

 This problem is a pain for all Web CGI programs, including ASP, Prel... etc., which can only be achieved by adding system components. Known as the most powerful Web CGI program: PHP, its performance in this regard is not disappointing, and even surpasses other CGI tools.

 The File Upload function is detailed in the RFC 1867 document, which uses a special file format (content-type) multipart/form-data. It is worth noting that the browser must be Netscape 3.0 or above or MS Internet Explorer 4.0 or above to upload files.

First look at the HTML source code below

< form enctype=&#39;multipart/form-data&#39; action=&#39;next.php&#39; method=post > 
您的大名: < input type=text name=user >< br > 
档案名称: < input name=&#39;myfile&#39; type=&#39;file&#39; >< br > 
< input type=&#39;submit&#39; value=&#39;送出&#39; > 
< /form >
Copy after login

In the form tag, the string enctype='multipart/form-data' must be added to indicate that the data entered by the user has files uploaded, and the method must be used POST and not GET.

 In the above code, if the user's name is filled in Wilson Peng and the file c:myphoto.gif is selected, after the user presses the send button, the browser will send the following POST material.

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

--AaB03x 
content-disposition: form-data; name=&#39;user&#39; 

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

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

...myphoto.gif 内容略... 
--BbC04y-- 
--AaB03x--
Copy after login

 Seeing in the above material, boundary=AaB03x is the message to leave the material in different fields. The encoding method of AaB03x varies depending on the version of the browser, and is usually generated by browser hashing. Then you can see that --AaB03x is used to separate different fields.

Taking the above example, the action program next.php that handles the form will automatically generate four variables, see the table below

Explanation of variable names
$myfile is the content of the uploaded file
$myfile_name is the real name of the uploaded file in the user
$myfile_size The size of the uploaded file
$myfile_type The format of the uploaded file, such as 'image/gif'


The most important thing to do in the next.php program is to make good use of these four variables, otherwise as soon as the program ends, The files uploaded by the user are lost. Therefore, you must first copy $myfile to the directory where the advertising images are stored.

copy($banner,&#39;/home1/biglobe3/ad/&#39;.$banner_name);
Copy after login

This program stores the file in the directory /home/htdocs/ad. In the above example, the file is saved in /home/ htdocs/ad/myphoto.gif. The important thing is that the directory where it is stored cannot be a directory that cannot be read by the Web Server, but should be placed in the directory where the homepage of the website is located so that it can be seen on the Internet.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template