用php实现广告轮播
网路广告,变成了 inte.net 上的热门学问。而 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 inte.net explorer 4.0 以上的版本才能将档案上传。
先看下面的 html 原始码
< form enctype="multipart/form-data" action="next.php" method=post >
您的大名: < input type=text name=user >< br >
档案名称: < input name="myfile" type="file" >< br >
< input type="submit" value="送出" >
< /form >
在 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 来隔开不同的栏位。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器