本文章收藏了一款简单php文件上传实例,这真的是一款超级简单的文件上传功能代码,利用php $files来获取要上传文件的,类型,名称与临时名称然后用move_uploaded_file把要上传文件保存到服务器指定目录就OK了.
html代码如下:
- <input type= "file " id= "userfile " name= "userfile ">
- <input type= "submit " name= "upload " value= "上传 ">
处理上传php代码,代码如下:
- <?php
- function do_upload($upload_dir,$upload_url)
- {
- $temp_name = $_files[ 'userfile '][ 'tmp_name '];
- $file_name = $_files[ 'userfile '][ 'name '];
- $file_name = str_replace( "\ ", " ",$file_name);
- $file_name = str_replace( " ' ", " ",$file_name);
- $file_path = $upload_dir.$file_name;
- $thistime=explode( "- ",date( "y-m-d-h-i-s "));
- $thistime=mktime();
- $filename=$thistime.substr($file_name,strrpos($file_name, ". "));
-
- if($file_name = ' ')
- {
- echo "文件名无效。 ";
- exit;
- }
- if(@move_uploaded_file($_files[ 'userfile '][ 'tmp_name '],$upload_dir.$filename))
- {
- echo "上传成功。 ";
- echo " <meta http-equiv= "refresh " content= "1;url=www.aimeige.com.cn.php "> ";
- exit;
- }else
- {
- echo "上传失败。 ";
- echo " <meta http-equiv= "refresh " content= "1;url=www.phpfensi.com.php "> ";
- exit;
- }
- echo "end ";
- }
- ?>
调用方法,代码如下:
- $upload_dir ='down.phpfensi.com'; $upload_url='www.phpfensi.com';
- do_upload($upload_dir,$upload_url) ;
|