<?php
$file_path="uploads/";
for($i=0;$i<count($_FILES[ufile][name]);$i++){
}
print_r($_FILES[ufile][name]);
$filename=$_FILES[ufile][name];
$filet=$_FILES[ufile][tmp_name];
if($filet[size]>"500000"){
}else if($filet){
}
else{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>无标题文档</title>
</head>
<body>
<p>请上传问件不大于500K</p>
<form method="post" action="upload.php" enctype="multipart/form-data">
</form>
</body>
</html>
案例二:
php动态批量上传文件
<?php
function upload_multi($path,$photo,$i){
$uploaddir = './'.$path;//文件存放目录
if(!file_exists($uploaddir))//如果目录不存在就新建
$uploaddir=mkdir($uploaddir);
$piece = explode('.',$photo['name'][$i]);
$uploadfile = $uploaddir . '/'.md5($piece[0]).'.'.$piece[1];
$result = move_uploaded_file($photo['tmp_name'][$i], $uploadfile);
if(!$result){
exit('上传失败');
}
return basename($uploadfile);
}
if($_POST['tijiao']){
extract($_POST);
$i=0;
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
upload_multi($email,$_FILES["pictures"],$i);
}
$i++;
}
}
?>
<script language="javascript">
function go_up(){
document.getElementByIdx_x_x_x_x_x('new_up').innerHTML+='<input type="file" name="pictures[]" /><br>';
}
</script>
<form action="file.php" method="post" enctype="multipart/form-data">
<p>多图片上传<br>
<input type="text" name="username" /><br>
<input type="text" name="email" /><br>
<input type="file" name="pictures[]" /><br>
<div id="new_up"></div>
<input type="button" " name="add_img" value="新增上传" οnclick="go_up()" /><br>
<input type="submit" value="Send" name="tijiao" /><br>
</p>
</form>
php文件上传代码(支持文件批量上传)
本款文件上传类,默认是上传单文件的,我们只要修改$inputname ='files'为你的表单名就可以方便的实现批量文件上传了。 $savename = ''保存文件名, $alowexts = array()设置允许上传的类型,$savepath = ''保存路径。
- */
-
- class
upload - {
- public
$savepath; - public
$files; - private
$error; -
- function
__construct($inputname ='files', $savepath = '', $savename = '', $alowexts = array(),$maxsize = 1024000) - {
- if(!$alowexts)$alowexts=explode('|',upload_ftype);
- $file_array=array();
- $savepath=str_replace('','/',$savepath);
- $savename=preg_replace('/[^a-z0-9_]+/i','',$savename);
- $this->savepath=substr($savepath,-1)=='/'?$savepath:$savepath.'/';
//路径名以/结尾 -
- if(!make_dir($this->savepath))
- {
- $this->error=8;
- $this->error();
- }
- //exit($this->savepath);
- if(!is_writeable($this->savepath))
- {
- $this->error=9;
- $this->error();
- }
- if(sizeof($_files[$inputname]['error'])>10)
- {
- $this->error=13;
- $this->error();
- }
- $max=sizeof($_files[$inputname]['error'])-1;
- //exit($this->savepath.$savename);
- foreach($_files[$inputname]['error']
as $key => $error) - {
- if($error==upload_err_ok)
//批量上传 - {
- $savename=$savename?$savename:date('ymdims').mt_rand(10000,99999);
- $fileext=strtolower(get_fileext($_files[$inputname]['name'][$key]));
- $savename=$savename.'.'.$fileext;
- $tmp_name=$_files[$inputname]['tmp_name'][$key];
- $filesize=$_files[$inputname]['size'][$key];
- if(!in_array($fileext,$alowexts))
- {
- $this->error=10;
- $this->error();
- }
- if($filesize>$maxsize)
- {
- $this->error=11;
- $this->error();
- }
- if(!$this->isuploadedfile($tmp_name))
- {
- $this->error=12;
- $this->error();
- }
-
- if(move_uploaded_file($tmp_name,$this->savepath.$savename)
|| @copy($tmp_name,$this->savepath.$savename)) - {
- //exit($this->savepath.$savename);
- @chmod($savename,
0644); - @unlink($tmp_name);
- $file_array[]=$this->savepath.$savename;
- }
- }
- else
- {
- $this->error=$error;
- $this->error();
- }
- unset($savename);
- }
- $this->files=$file_array;
- return
true; - }
-
- function
isuploadedfile($file) //去掉系统自带的反斜线 - {
- return
(is_uploaded_file($file) || is_uploaded_file(str_replace('\','',$file))); - }
-
- function
error() - {
- $upload_error=array(0
=> '文件上传成功 !', - 1
=> '上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值 !', - 2
=> '上传文件的大小超过了 html 表单中 max_file_size 选项指定的值 !', - 3
=> '文件只有部分被上传 !', - 4
=> '没有文件被上传 !', - 5
=> '未知错误!', - 6
=> '找不到临时文件夹。 !', - 7
=> '文件写入临时文件夹失败 !', - 8
=> '附件目录创建失败 !', - 9
=> '附件目录没有写入权限 !', - 10
=> '不允许上传该类型文件 !', - 11
=> '文件超过了管理员限定的大小 !', - 12
=> '非法上传文件 !', - 13
=> '最多可同时上传10个文件 !' - );
- showmsg($upload_error[$this->error]);
- }
-
- }
- //使用方法
-
- new
upload();
案例四:PHP文件批量上传类
<?php
class
{
}
?>
案例五:php批量上传,里面没写上php的文件名们应该是:up.php
PHP批量上传文件
以下是本人做的一个批量上传的php程序,请参考!
首先,创建一个upload.html;内容如下:
<html
<head>
<meta
<title>
</title>
<script
function
div
div.style.display='block';
document.getElementByIdx_x_x('fade').style.display='block';
childs
for(i=0;i<childs.length;i++){
if(childs[i].nodeName.toUpperCase()
childs[i].src="funs/up.php?label="+id;
}
}
}
//删除元素
function
a
child
a.removeChild(child);
}
//添加元素
function
span
span.id
span.style.display
span.style.height
span.style.lineHeight
span.innerHTML
return
}
function
div
mynum
//mynum
document.getElementByIdx_x_x("num").value
obj
div.a(obj);
}
</script>
<style
.white_content
display:none;
position:absolute;
width:40%;
top:25%;
left:30%;
z-index:9999;
background-color:#fff;
}
.black_overlay{
display:none;
width:100%;
height:100%;
background-color:#ccc;
position:absolute;
top:0;
left:0;
z-index:1;
filter:
-moz-opacity:.5;
opacity:0.5;
</style>
</head>
<body>
<div
</div>
<div
<table
<input
</div>
</body>
</html>
然后在本目录创建一个funs的文件夹,人后在里面创建一个php文件,放在,内容如下:
//上传文件类型列表
$uptypes=array(
);
$max_file_size=2000000;
$destination_folder="../uploadimg/";
?>
<html>
<head>
<title>添加上传图片</title>
<style
<!--
body
{
}
input,
-->
</style>
</head>
<body>
<form
</form>
<?php
if
{
?>
<?php
if(isset($_GET['label'])){//如果是批量上传?>
window.parent.document.getElementByIdx_x_x("pic_name<?php
window.parent.document.getElementByIdx_x_x("pic_url<?php
window.parent.document.getElementByIdx_x_x('light').style.display='none';
window.parent.document.getElementByIdx_x_x('fade').style.display='none';
window.close();
<?php
else{?>
window.parent.document.thisform.uploadfile.value='uploadimg/<?=$fname?>';
window.parent.document.getElementByIdx_x_x("success").innerHTML=("上传成功!
<?php
}
?>
</body>
完成,当然,在保存图片的时候可以自己添加保存缩略图的代码,具体自己扩展,仅供参考