<input type="file" name="picurl[]" value="" />
<?
for( $i = 0 ; $i <= 2 ;$i++){
if($_FILES[picurl]['tmp_name']){
$upload  = new discuz_upload();
$upload->init($_FILES['picurl']);
$attr = & $upload->attach;
$save_path = 'pic/'.dgmdate(TIMESTAMP,'Y').'/'.dgmdate(TIMESTAMP,'m').'/'.dgmdate(TIMESTAMP,'j').'/';
$lang_path = $_G['setting']['attachdir'].$save_path;
if(!is_dir($lang_path))dmkdir($lang_path,0777);
$attr['target']=$lang_path.$attr['attachment'];
$upload->save();
$arr['picurl'] = $save_path.$attr['attachment'];
}

?>
file 是单个文件的时候可以,我加上数组后就不行了。[$i]  这个变量应该怎么加进去

解决方案 »

  1.   


      <form name="form1" method="post" action="demo.php" enctype="multipart/form-data">
       <input type="file" name="picurl[]">
       <input type="file" name="picurl[]">
       <input type="submit" name="b1">
      </form><?php
    print_r($_FILES);
    ?>Array
    (
        [picurl] => Array
            (
                [name] => Array
                    (
                        [0] => 1.jpg
                        [1] => 2.jpg
                    )            [type] => Array
                    (
                        [0] => image/jpeg
                        [1] => image/jpeg
                    )            [tmp_name] => Array
                    (
                        [0] => G:\wamp\tmp\phpF7.tmp
                        [1] => G:\wamp\tmp\phpF8.tmp
                    )            [error] => Array
                    (
                        [0] => 0
                        [1] => 0
                    )            [size] => Array
                    (
                        [0] => 51798
                        [1] => 119445
                    )        ))
      

  2.   

    把php部分改为foreach ( $_FILES [ "picurl" ][ "tmp_name" ] as  $key  =>  $v ) {
        $tmp_name  =  $_FILES [ "picurl" ][ "tmp_name" ][ $key ];
        $name  =  $_FILES [ "picurl" ][ "name" ][ $key ];
        move_uploaded_file ( $tmp_name ,  "$name" );
    }
    就能上传了。
      

  3.   

    我是改的dz系统,必须得用
    $upload  = new discuz_upload();$upload->init($name);$attr = & $upload->attach;
    这个才能上传。有办法融合一下吗
      

  4.   

    看过discuz_upload的源码,不支持批量上传。