Home  >  Article  >  Backend Development  >  一个或多个文件下传-php

一个或多个文件下传-php

WBOY
WBOYOriginal
2016-06-13 11:00:27886browse

一个或多个文件上传--php

?

<?php /* * 作者  可可 * 日期  2011-1-20 *//* * $field 指定form表单中的input字段名 * $type 指定上传的文件类型 * $dir  指定文件保存的路径,相对于站点根路径的相对路径(以/开始和结尾) * $maxsize 限制上传文件的大小(单位字节),默认不限制 * 返回值 "error"代表上传错误,"type"代表类型不允许,"size"代表文件太大,上传成功返回保存后的文件名 */function uploadfile($field,$type,$dir,$maxsize=0){ if($_FILES[$field]!=null){  $file=$_FILES[$field];  if($file[error]==1)return "error";  if($type!=strstr($file[type],"/",true))return "type";  if($maxsize>0&&$file[size]>$maxsize)return "size";  if(!is_dir($dir))mkdir($dir);  list($second,$unix)=explode(" ",microtime());  $name=$unix.($second*100000000).strstr($file[name],".");//根据时间为上传的文件重新命名,精确到微秒  move_uploaded_file($file[tmp_name], $dir.$name);  return $name; }}/* * $field 指定form表单中的input字段名最后以[]结尾,例如:image[] */function uploadfile_table($field,$type,$dir,$maxsize=0){ if($_FILES[$field]!=null){  $file=$_FILES[$field];  $count=count($file[name]);  $arr=array();  if(!is_dir($dir))mkdir($dir);  for($i=0;$i0&&$file[size][$i]>$maxsize){    $arr[$i]="size";    continue;   }   list($second,$unix)=explode(" ",microtime());   $name=$unix.($second*100000000).strstr($file[name][$i],".");   move_uploaded_file($file[tmp_name][$i], $dir.$name);   $arr[$i]=$name;  }  return $arr;  } }echo "<pre class="brush:php;toolbar:false">";//print_r(uploadfile("upimage", "image", $_SERVER['DOCUMENT_ROOT']."/picture/",5120));//上传单个文件print_r(uploadfile_table("upimage", "image", $_SERVER['DOCUMENT_ROOT']."/picture/"));//上传多个文件echo "
"?>

?

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>上传多个文件</title>
?

?

Statement:
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
Previous article:php中容易的检测函数Next article:归藏各种PHP写的类