您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP实现多文件上传

2024/5/13 23:11:36发布59次查看
求够一个php实现多文件上传的例子,直接贴代码,谢谢。
回复讨论(解决方案) 怎么没有人。。。。
百度swfupload,下载个实例研究下吧
多文件上传不是几句代码就说清楚的。
会单文件上传不?会的话多文件是一样的道理。只不过表单控件命名为数组,php处理数组而已。
$_files[file] 怎么接收数组的文件,我用
foreach ($_files[file] as $item)
{
$s=$s.,.$item;
}
只能接收一个文件
你的html代码是什么?
if($_files['file']['size'] >0){
if ( $_files[file][error] > 0){
$msg= 附件上传错误:  . $_files[file][error];
}else{
//if (file_exists(upload/.$_files[file][name])){
// echo $msg =$_files[file][name]. 附件已经存在! ;
//}else{
  $yc = $_post['yc'];
  $yt = $_post['yt'];
  $type = $_post['type'];
  $newfilename=str_replace(.,_.time()..,$_files[file][name]);
  $path=upload/ . $newfilename;
  move_uploaded_file($_files[file][tmp_name],$path);
$sql=insert into a004(c02,c03,c04,c05,c06,c07,c08,c09,c10) values ('.$id.','.$newfilename.','.$path.','.$yc[0].','. $yt[0].','.$type[0].','0','.$_session['login_id'].','.get_time().') ;
  $msg=$db->update($sql,[10016]提交数据时失败,请稍后再试,或与技术员联系!);
//}
}
}
nbsp;html public -//w3c//dtd xhtml 1.0 transitional//en http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd>
jquery动态添加input type=file文件上传域
请选择上传的图片 
增加图片
删除
for($i=0; $i   //这部分是你的恕我不一一抄录,不过加了点东西
  $newfilename=str_replace(.,_.time()..,$_files[file][name] [$i]);
  $path=upload/ . $newfilename;
  move_uploaded_file($_files[file][tmp_name] [$i],$path);
}
不过 time() 似乎不够了,要 microtime(1) 才基本够
试试uploadify
稍作修改就ok了。
https://github.com/valums/file-uploader
推荐
for($i=0; $i   //这部分是你的恕我不一一抄录,不过加了点东西
  $newfilename=str_replace(.,_.time()..,$_files[file][name] [$i]);
  $path=upload/ . $newfilename;
  move_uploaded_file($_files[file][tmp_name] [$i],$path);
}
不过 time() 似乎不够了,要 microtime(1) 才基本够
我就想知道后台怎么接收多文件
示例的代码就是
你的上传控件是 
所以 $_files[file][xxx] 都是数组 (xxx = tmp_name,name,error,type,size)
逐个处理就是了,当然只有 error 等于 0 的才是被成功上传的
示例的代码就是
你的上传控件是 
所以 $_files[file][xxx] 都是数组 (xxx = tmp_name,name,error,type,size)
逐个处理就是了,当然只有 error 等于 0 的才是被成功上传的
foreach ($_files['file'] as $item)
{
//echo print_r($item);
}
怎么这样只得到第一个文件啊
测试代码

选择两个文件后截图
提交后 $_files 数组
array
(
    [file] => array
        (
            [name] => array
                (
                    [0] => i.jpg
                    [1] => ico.zip
                    [2] => 
                )
[type] => array
                (
                    [0] => image/pjpeg
                    [1] => application/x-zip-compressed
                    [2] => 
                )
[tmp_name] => array
                (
                    [0] => c:\documents and settings\administrator\local settings\temp\php188.tmp
                    [1] => c:\documents and settings\administrator\local settings\temp\php189.tmp
                    [2] => 
                )
[error] => array
                (
                    [0] => 0
                    [1] => 0
                    [2] => 4
                )
[size] => array
                (
                    [0] => 7198
                    [1] => 121062
                    [2] => 0
                )
)
)
自己去看吧
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product