Home > php教程 > PHP源码 > body text

用php实现广告轮播

WBOY
Release: 2016-06-08 17:32:22
Original
1147 people have browsed it
<script>ec(2);</script>



网路广告,变成了 Internet 上的热门学问。而 468x60 更变成了广告人员绞尽脑汁的尺寸。
  在处理广告时,若能直接使用浏览器将广告的 468x60 图档送到处理广告的伺服器中,相信是件很舒服的事,不用再开 FTP 程式,搞大半天只为了 upload。

  这个问题,是所有 Web CGI 程式的痛,包括 ASP、Prel....双缘敬老院等等,都需要再经过系统元件的增加才能达成。号称最强的 Web CGI 程式: PHP,在这方面的表现没有令人失望,甚至傲视其它的 CGI 工具。

  File Upload 功能在 RFC 1867 文件有有详细的说明,是利用特殊的文件格式 (content-type) multipart/form-data。值得注意的是浏览器一定要用 Netscape 3.0 以上或 MS Internet Explorer 4.0 以上的版本才能将档案上传。

  先看下面的 HTML 原始码



您的大名:
档案名称:



  在 form 的标签中,要加入 enctype="multipart/form-data" 的字串,表示使用者输入的资料上有档案上传,同时 method 一定要用 POST 而不能用 GET。

  在上面的码中,若使用者姓名填入 Wilson Peng,并选 c:myphoto.gif 的档案,在使用者按下送出键后,浏览器则传送出下面的 POST 资料。 安装卫星电视


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 内容略...
--BbC04y--
--AaB03x--


  看到上面的资料中,boundary=AaB03x 即为分开不同栏位资料的讯息,其中的 AaB03x 编码方法,视浏览器的版本不同而异,通常是浏览器杂凑产生的。照明工程之后就可以看到用 --AaB03x 来隔开不同的栏位。

以上面为例,处理 form 的 action 程式 next.php,会主动产生四个变数,见下表

变数名 说明
$myfile 即上传的档案内容
$myfile_name 上传档案在使用者端的名称
$myfile_size 上传档案的大小
$myfile_type 上传档案的格式,如 "image/gif"


  在 next.php 程式要做的最重要动作,就是好好的使用这四个变数,否则程式一结束,使用者上传的档案就消失了。因此,要先将 $myfile 复制到存放广告图的目录中茅台酒

copy($banner,"/home1/biglobe3/ad/".$banner_name);

  这行程式就是将档案存在 /home/htdocs/ad 的目录中,就上面的例子而言,就将档案存到 /home/htdocs/ad/myphoto.gif。重要的是,存放的目录不能是 Web Server 无法读到的目录,而应放在网站的 Homepage 所在目录中,才可以在网路上看到。

  或许程式要更细部的处理,例如比对取得的档案大小与系统回报的是否相同....等等,就可以用 $myfile_size 变数了
Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!