-
-
-
$uptypes=array(
- //上传文件的ContentType格式
- 'image/jpg',
- 'image/jpeg',
- 'image/png',
- 'image/pjpeg',
- 'image/gif',
- 'image/bmp',
- 'image/x-png',
- 'application/msword',//doc
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',//docx
- 'application/vnd.openxmlformats-officedocument.presentationml.presentation',//pptx
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',//xlsx
- 'text/plain'
- );
- /**
- * php多文件、多图片上传
- * by bbs.it-home.org
- */
- $max_file_size=2000000; //上传文件大小限制, 单位BYTE
- $dir="upload/"; //上传文件路径
- if ($_SERVER['REQUEST_METHOD'] == 'POST')
- {
- $file = $_FILES['upfile']['name'];
- foreach($file as $key=>$item){
- if($item != ''){
- if (!is_uploaded_file($_FILES['upfile']['tmp_name'][$key]))//是否存在文件
- {
- echo "图片不存在!";
- exit;
- }
- if($max_file_size {
- echo "文件太大!";
- exit;
- }
- if(!file_exists($dir))
- {
- mkdir($dir);
- }
- $filename=$_FILES['upfile']['tmp_name'][$key];
- $image_size = getimagesize($filename);
- $pinfo = pathinfo($file[$key]);
-
- $ftype = $pinfo['extension'];
- $destination = $dir.time().$file[$key];
- if (file_exists($destination) && $overwrite != true)
- {
- echo "同名文件已经存在了";
- exit;
- }
-
- if(!move_uploaded_file ($filename, $destination))
- {
- echo "移动文件出错";
- exit;
- }
- $pinfo=pathinfo($destination);
- $fname=$pinfo['basename'];
- echo " 已经成功上传
文件名: ".$dir.$fname." ";
- echo " 宽度:".$image_size[0];
- echo " 长度:".$image_size[1];
- echo "
大小:".$_FILES['upfile']['size']." bytes";
-
- }
-
- echo "
图片预览: ";
- echo "";
- echo "
";
- }
- }
-
- ?>
-
复制代码
说明:
上传时,需要上传两个,否则会报错。
代码不是很完善,只是给出一个思路,仅供学习参考。
|