欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

一次上传多个文件_PHP教程

程序员文章站 2022-06-10 19:15:19
...
一次上传多个文件

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


最佳答案[url=http://www.111cn.cn/bbs/space.php?username=E网逍遥]链接标记E网逍遥[/url]
[url=http://www.111cn.cn/bbs/space.php?uid=58710]链接标记[img]http://www.111cn.cn/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 上载失败
  • ";

    }

    }

    }

    ?>







    动态多文件上传











































    复制代码



    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 上载失败
  • ";

    }

    }

    }

    ?>







    动态多文件上传











































    复制代码


    www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632542.htmlTechArticle一次上传多个文件 [img]http://file:///D:/1.jpg[/img] 请问下这种类型的能随意增加减少上传图片的input要怎么实现,有人能帮我写个这样的代码么...