PHP新手上路(十四)
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-05-24
_type; global $local_file, $error_msg; global $HTTP_REFERER; if ( $userfile == "none" ) { $error_msg = "You did not specify a file for uploading."; return; } if ( $userfile_size > 2000000 ) { $error_msg = "Sorry, your file is too large."; return; } // Wherever you have write permission below... $upload_dir = "photos"; $local_file = "$upload_dir/$userfile_name"; if ( file_exists ( $local_file ) ) { $error_msg = "Sorry, a file with that name already exists"; return; }; // 你还可以由此检查文件名称/类型对以确定是何种文件:gif,jpg,mp3… rename($userfile, $local_file); echo "The file is uploaded<BR>n"; echo "<A HREF="$HTTP_REFERER">Go Back</A><BR>n"; } $title = "Upload File"; include("include/header.inc"); if (empty($userfile) || $userfile=="none") { // 输出以下表单 ?> <FORM ACTION="<? echo "$PHP_SELF"; ?>" ENCTYPE="multipart/form-data" METHOD=POST> <INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="2000000"> <INPUT TYPE="FILE" NAME="userfile" SIZE="24" MAXLENGTH="80"> <BR><BR> <INPUT TYPE="SUBMIT" VALUE="Upload File!" NAME="sendit"> <INPUT TYPE="SUBMIT" VALUE="Cancel" NAME="cancelit"><BR> </FORM> <I><FONT SIZE="2">(You may notice a slight delay while we upload your file.)</FONT></I> <? } else { if ( $error_msg ) { echo "<B>$error_msg</B><BR><BR>"; } if ( $sendit ) { do_upload (); } } include("include/footer.inc"); ?> 照片图库 <? include("include/common.inc"); $title = "Gallery"; include("include/header.inc"); ?> <P> Here are some of our family photos. This PHP script can really be made better, by splitting into multiple pages. </P> <? $d = dir("photos"); while($entry = $d->read()) { if (is_file("photos/$entry")) echo "<IMG SRC="photos/$entry">n"; } $d->close(); ?> <? include("include/footer.inc"); ?> 另外,你可以在文件上传的表单中加上一个输入元素去描述该上传的文件。这个元素将被存储在文件中,然后被以上的照片图库的那段代码所读出并显示出来。 |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: php5中this,self,parent的意义下一篇: PHP简介
关于PHP新手上路(十四)的所有评论