当前位置:编程学习 > php >>

一次上传多个文件




一次上传多个文件

[img]http://file:///D:/1.jpg[/img]
请问下这种类型的能随意增加减少上传图片的input要怎么实现,有人能帮我写个这样的代码么?且并接收的页面要能成功的接收到这边传过去的图片


最佳答案[url=http://www.226511.com/bbs/space.php?username=E网逍遥]链接标记E网逍遥[/url]
[url=http://www.226511.com/bbs/space.php?uid=58710]链接标记[img]http://www.226511.com/server/avatar.php?uid=58710&size=small[/img][/url]

$ScriptName = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];

$mname = "xchngg";

$mpass = "123456";

$mpath = trim($_POST['mpath']);

$Submit = trim($_POST['Submit']);

$action = trim($_GET['action']);

$username = trim($_POST['username']);

$password = trim($_POST['password']);

if($Submit != "" && $mname == $username && $mpass == $password){

if($mpath != "")$mpath = $mpath."/"; //上传路径

foreach($_FILES['fname']['name'] as $key=>$val){ //数组上传文件

$fname = $mpath.$val;

if ( $_FILES['fname']['error'][$key]>0 || $_FILES['fname']['size'][$key]==0) {

continue;

}

if (@move_uploaded_file($_FILES['fname']['tmp_name'][$key], $fname)) { //上传文件

$message .="
  • $val 上载成功(".$_FILES['fname']['size'][$key]."字节)
  • ";

    $file_num ++;

    }else{

    $stat = "error";

    $message .="
  • $val 上载失败
  • ";

    }

    }

    }

    ?>







    动态多文件上传

































    3个文件准备上传



















    上传路径:



    用户名:



    密码:































    复制代码



    D8888D回贴内容-------------------------------------------------------


    $ScriptName = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];

    $mname = "xchngg";

    $mpass = "123456";

    $mpath = trim($_POST['mpath']);

    $Submit = trim($_POST['Submit']);

    $action = trim($_GET['action']);

    $username = trim($_POST['username']);

    $password = trim($_POST['password']);

    if($Submit != "" && $mname == $username && $mpass == $password){

    if($mpath != "")$mpath = $mpath."/"; //上传路径

    foreach($_FILES['fname']['name'] as $key=>$val){ //数组上传文件

    $fname = $mpath.$val;

    if ( $_FILES['fname']['error'][$key]>0 || $_FILES['fname']['size'][$key]==0) {

    continue;

    }

    if (@move_uploaded_file($_FILES['fname']['tmp_name'][$key], $fname)) { //上传文件

    $message .="
  • $val 上载成功(".$_FILES['fname']['size'][$key]."字节)
  • ";

    $file_num ++;

    }else{

    $stat = "error";

    $message .="
  • $val 上载失败
  • ";

    }

    }

    }

    ?>







    动态多文件上传

































    3个文件准备上传



















    上传路径:



    用户名:



    密码:































    复制代码


    补充:Php教程,常见问题
    CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
    部分文章来自网络,