php文件上传类(该类支持单个或者多个文件上传)(1/2)

 更新时间:2016年11月25日 16:28  点击:1491
这个文件上传类可以实现多个文件或单个文件进行上传了,下面小编来给各位推荐一个不错的例子。

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<?php
//php文件上传类(该类支持单个或者多个文件上传)
 /**
 * 类名:upfile
 * 作用:处理文件上传
 * 说明,该类处理单个或者多个文件上传,使用该类时,只需要实列化该类
 * 例:
 * $up = upfile()
 * $up->update_file($_file['filename'])
 *
 * $up->update_file   函数返回一个数组,如果是多文件上传,则为多维数据。
 * 数组的内容:
 * $fileinfo['file_size']   上传文件的大小
 * $fileinfo['file_suffix'] 上传文件的类型
 * $fileinfo['file_name']   上传文件的名字
 * $fileinfo['error']     上传文件产生的错误
 *

 */
class upfile {
 public $fcount = 1;           //上传文件的数量
 public $ftype  = array('jpg','jpeg','gif','png');  //文件格式
 public $fsize  = 1024;          //文件大小单位kb
 public $fdir   = 'www.111cn.net/';         //文件存放目录
 public $errormsg = '';          //产生的临时错误信息

 /**
  *函数名:get_tmp_file($putfile)
  *作用:取得上传的临时文件名
  *@param array $putfile
  *@return string $upimg 返回临时文件名
  */
  function get_tmp_file($putfile){
  if($this->fcount == 1){
   $tmpfile = $putfile['tmp_name'];
  }else{
   for($i=0;$i<$this->fcount;$i++){
    $tmpfile[] = $putfile['tmp_name'][$i];
   }
  }
  return $tmpfile;
  }

关于购物车,这个是在电子商务方面使用的比较多,用户选择好自己的商品需要保存起来,最后去收银台,这很像我们实际生活的超市,所以我现来写一个简单的php购物车实例代码,比较详细只要一步步,处理好就OK了。

些购物车会用到php文件
 main.php 显示商品
 additem.php把商品加入购物车
 cearcart.php删除购物车中的商品
 shoppingcart.php 操作类
 
用户的数据库教程有

 代码如下 复制代码
 inventory
  create table inventory (
    product tinytext not null,
    quantity tinytext not null,
    id int(4) default '0' not null auto_increment,
    description tinytext not null,
    price float(10,2) default '0.00' not null,
    category char(1) default '' not null,
    key id (id),
    primary key (id),
    key price (price)
  );
  insert into inventory values ('硬盘','5','1','80g','5600','1');
  insert into inventory values ('cpu','12','2','p4-2.4g','6600','1');
  insert into inventory values ('dvd-rom','7','3','12x','2000','1');
  insert into inventory values ('主板www.111cn.net','3','4','asus','5000','2');
  insert into inventory values ('显示卡','6','5','64m','4500','1');
  insert into inventory values ('刻录机','4','6','52w','3000','1');
 
 shopping
  create table shopping (
    session tinytext not null,
    product tinytext not null,
    quantity tinytext not null,
    card tinytext not null,
    id int(4) default '0' not null auto_increment,
    key id (id),
    primary key (id)
  );
 shopper
 
  create database shopper;
  use shopper;
  create table shopping (
    session tinytext not null,
    product tinytext not null,
    quantity tinytext not null,
    card tinytext not null,
    id int(4) default '0' not null auto_increment,
    key id (id),
    primary key (id)
  );
  create table inventory (
    product tinytext not null,
    quantity tinytext not null,
    id int(4) default '0' not null auto_increment,
    description tinytext not null,
    price float(10,2) default '0.00' not null,
    category char(1) default '' not null,
    key id (id),
    primary key (id),
    key price (price)
  );
  insert into inventory values ('硬盘','5','1','80g','5600','1');
  insert into inventory values ('cpu','12','2','p4-2.4g','6600','1');
  insert into inventory values ('dvd-rom','7','3','12x','2000','1');
  insert into inventory values ('主板111cn.net','3','4','asus','5000','2');
  insert into inventory values ('显示卡','6','5','64m','4500','1');
  insert into inventory values ('刻录机','4','6','52w','3000','1');

*/

//main.php 显示购物车所有商品

 代码如下 复制代码

include("shoppingcart.php");
$cart = new cart;
$table="shopping";

/* 查询并显示所有存货表中的信息 */
    $query = "select * from inventory";
    $invresult = mysql教程_query($query);
    if (!($invresult)) {
       echo "查询失败<br>";
       exit;
    }
    echo "以下产品可供订购∶";
    echo "<table border=0>";
    echo "<tr><td bgcolor=#aaccff>产品编号</td><td bgcolor=#aaccff>产品名称</td><td bgcolor=#aaccff>单价</td>";
    echo "<td bgcolor=#aaccff>剩余数量</td><td bgcolor=#aaccff>产品描述</td><td bgcolor=#aaccff>放入购物车</td></tr>";
    while($row_inventory = mysql_fetch_object($invresult)) {
    echo "<tr><td bgcolor=#aaccff>".$row_inventory->id."</td>";
    echo "<td bgcolor=#aaccff>".$row_inventory->product."</td>";
    echo "<td bgcolor=#aaccff>".$row_inventory->price."</td>";
    echo "<td bgcolor=#aaccff>".$row_inventory->quantity."</td>";
    echo "<td bgcolor=#aaccff>".$row_inventory->description."</td>";
    echo "<td bgcolor=#aaccff><a href='additem.php?product=".$row_inventory->product."'><img border='0' src='cart.gif' width='81' height='17'></a></td></tr>";
    }
    echo "</table>";
    echo "<br>购物车中产品的数量∶".$cart->quant_items($table, $session);
    echo "<br><br><a href='clearcart.php'><img border='0' src='car.gif'></a>清空购物车";

 

在php文件上传这一款,如果不用ajax来实现,效果都不怎么样,用户体验不怎么好,下面我们就来看看这一款ajax+php 无刷新文件上传代码吧。ajax+php 无刷新文件上传代码

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>ajax+php 无刷新文件上传代码</title>
</head>
<body>
<style>
.fu_list {
 width:600px;
 background:#ebebeb;
 font-size:12px;
}
.fu_list td {
 padding:5px;
 line-height:20px;
 background-color:#fff;
}
.fu_list table {
 width:100%;
 border:1px solid #ebebeb;
}
.fu_list thead td {
 background-color:#f4f4f4;
}
.fu_list b {
 font-size:14px;
}
/*file容器样式*/
a.files {
 width:90px;
 height:30px;
 overflow:hidden;
 display:block;
 border:1px solid #bebebe;
 background:url(img/fu_btn.gif) left top no-repeat;
 text-decoration:none;
}
a.files:hover {
 background-color:#ffffee;
 background-position:0 -30px;
}
/*file设为透明,并覆盖整个触发面*/
a.files input {
 margin-left:-350px;
 font-size:30px;
 cursor:pointer;
 filter:alpha(opacity=0);
 opacity:0;
}
/*取消点击时的虚线框*/
a.files, a.files input {
 outline:none;/*ff*/
 hide-focus:expression(this.hidefocus=true);/*ie*/
}
</style>
<form id="uploadform" action="file.php">
  <table border="0" cellspacing="1" class="fu_list">
    <thead>
      <tr>
        <td colspan="2"><b>上传文件</b></td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td align="right" width="15%" style="line-height:35px;">添加文件:</td>
        <td><a href="网页特效:void(0);" class="files" id="idfile"></a> <img id="idprocess" style="display:none;" src="img/loading.gif" /></td>
      </tr>
      <tr>
        <td colspan="2"><table border="0" cellspacing="0">
            <thead>
              <tr>
                <td>文件路径</td>
                <td width="100"></td>
              </tr>
            </thead>
            <tbody id="idfilelist">
            </tbody>
          </table></td>
      </tr>
      <tr>
        <td colspan="2" style="color:gray">温馨提示:最多可同时上传 <b id="idlimit"></b> 个文件,只允许上传 <b id="idext"></b> 文件。 </td>
      </tr>
      <tr>
        <td colspan="2" align="center" id="idmsg"><input type="button" value="开始上传" id="idbtnupload" disabled="disabled" />
          &nbsp;&nbsp;&nbsp;
          <input type="button" value="全部取消" id="idbtndel" disabled="disabled" />
        </td>
      </tr>
    </tbody>
  </table>
</form>
<script type="text/网页特效">

var isie = (document.all) ? true : false;

var $ = function (id) {
    return "string" == typeof id ? document.getelementbyid(id) : id;
};

var class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

var extend = function(destination, source) {
 for (var property in source) {
  destination[property] = source[property];
 }
}

var bind = function(object, fun) {
 return function() {
  return fun.apply(object, arguments);
 }
}

var each = function(list, fun){
 for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
};

//文件上传类
var fileupload = class.create();
fileupload.prototype = {
  //表单对象,文件控件存放空间
  initialize: function(form, folder, options) {
 
 this.form = $(form);//表单
 this.folder = $(folder);//文件控件存放空间
 this.files = [];//文件集合
 
 this.setoptions(options);
 
 this.filename = this.options.filename;
 this._framename = this.options.framename;
 this.limit = this.options.limit;
 this.distinct = !!this.options.distinct;
 this.extin = this.options.extin;
 this.extout = this.options.extout;
 
 this.oninifile = this.options.oninifile;
 this.onempty = this.options.onempty;
 this.onnotextin = this.options.onnotextin;
 this.onextout = this.options.onextout;
 this.onlimite = this.options.onlimite;
 this.onsame = this.options.onsame;
 this.onfail = this.options.onfail;
 this.onini = this.options.onini;
 
 if(!this._framename){
  //为每个实例创建不同的iframe
  this._framename = "uploadframe_" + math.floor(math.random() * 1000);
  //ie不能修改iframe的name
  var oframe = isie ? document.createelement("<iframe name="" + this._framename + "">") : document.createelement("iframe");
  //为ff设置name
  oframe.name = this._framename;
  oframe.style.display = "none";
  //在ie文档未加载完用appendchild会报错
  document.body.insertbefore(oframe, document.body.childnodes[0]);
 }
 
 //设置form属性,关键是target要指向iframe
 this.form.target = this._framename;
 this.form.method = "post";
 //注意ie的form没有enctype属性,要用encoding
 this.form.encoding = "multipart/form-data";

 //整理一次
 this.ini();
  },
  //设置默认属性
  setoptions: function(options) {
    this.options = {//默认值
  filename: "files[]",//文件上传控件的name,配合后台使用
  framename: "",//iframe的name,要自定义iframe的话这里设置name
  oninifile: function(){},//整理文件时执行(其中参数是file对象)
  onempty: function(){},//文件空值时执行
  limit:  10,//文件数限制,0为不限制
  onlimite: function(){},//超过文件数限制时执行
  distinct: true,//是否不允许相同文件
  onsame:  function(){},//有相同文件时执行
  extin:  ["gif","jpg","rar","zip","iso","swf","exe"],//允许后缀名
  onnotextin: function(){},//不是允许后缀名时执行
  extout:  [],//禁止后缀名,当设置了extin则extout无效
  onextout: function(){},//是禁止后缀名时执行
  onfail:  function(){},//文件不通过检测时执行(其中参数是file对象)
  onini:  function(){}//重置时执行
    };
    extend(this.options, options || {});
  },
  //整理空间
  ini: function() {
 //整理文件集合
 this.files = [];
 //整理文件空间,把有值的file放入文件集合
 each(this.folder.getelementsbytagname("input"), bind(this, function(o){
  if(o.type == "file"){ o.value && this.files.push(o); this.oninifile(o); }
 }))
 //插入一个新的file
 var file = document.createelement("input");
 file.name = this.filename; file.type = "file"; file.onchange = bind(this, function(){ this.check(file); this.ini(); });
 this.folder.appendchild(file);
 //执行附加程序
 this.onini();
  },
  //检测file对象
  check: function(file) {
 //检测变量
 var bcheck = true;
 //空值、文件数限制、后缀名、相同文件检测
 if(!file.value){
  bcheck = false; this.onempty();
 } else if(this.limit && this.files.length >= this.limit){
  bcheck = false; this.onlimite();
 } else if(!!this.extin.length && !regexp(".(" + this.extin.join("|") + ")$", "i").test(file.value)){
  //检测是否允许后缀名
  bcheck = false; this.onnotextin();
 } else if(!!this.extout.length && regexp(".(" + this.extout.join("|") + ")$", "i").test(file.value)) {
  //检测是否禁止后缀名
  bcheck = false; this.onextout();
 } else if(!!this.distinct) {
  each(this.files, function(o){ if(o.value == file.value){ bcheck = false; } })
  if(!bcheck){ this.onsame(); }
 }
 //没有通过检测
 !bcheck && this.onfail(file);
  },
  //删除指定file
  delete: function(file) {
 //移除指定file
 this.folder.removechild(file); this.ini();
  },
  //删除全部file
  clear: function() {
 //清空文件空间
 each(this.files, bind(this, function(o){ this.folder.removechild(o); })); this.ini();
  }
}

var fu = new fileupload("uploadform", "idfile", { extin: ["gif","jpg"],
 oninifile: function(file){ file.value ? file.style.display = "none" : this.folder.removechild(file); },
 onempty: function(){ alert("请选择一个文件"); },
 onlimite: function(){ alert("超过上传限制"); },
 onsame: function(){ alert("已经有相同文件"); },
 onnotextin: function(){ alert("只允许上传" + this.extin.join(",") + "文件"); },
 onfail: function(file){ this.folder.removechild(file); },
 onini: function(){
  //显示文件列表
  var arrrows = [];
  if(this.files.length){
   var othis = this;
   each(this.files, function(o){
    var a = document.createelement("a"); a.innerhtml = "取消"; a.href = "javascript:void(0);";
    a.onclick = function(){ othis.delete(o); return false; };
    arrrows.push([o.value, a]);
   });
  } else { arrrows.push(["<font color='gray'>没有添加文件</font>", "&nbsp;"]); }
  addlist(arrrows);
  //设置按钮
  $("idbtnupload").disabled = $("idbtndel").disabled = this.files.length <= 0;
 }
});

$("idbtnupload").onclick = function(){
 //显示文件列表
 var arrrows = [];
 each(fu.files, function(o){ arrrows.push([o.value, "&nbsp;"]); });
 addlist(arrrows);
 
 fu.folder.style.display = "none";
 $("idprocess").style.display = "";
 $("idmsg").innerhtml = "正在添加文件到您的网盘中,请稍候……<br />有可能因为网络问题,出现程序长时间无响应,请点击"<a href='?'><font color='red'>取消</font></a>"重新上传文件";
 
 fu.form.submit();
}

//用来添加文件列表的函数
function addlist(rows){
 //根据数组来添加列表
 var filelist = $("idfilelist"), ofragment = document.createdocumentfragment();
 //用文档碎片保存列表
 each(rows, function(cells){
  var row = document.createelement("tr");
  each(cells, function(o){
   var cell = document.createelement("td");
   if(typeof o == "string"){ cell.innerhtml = o; }else{ cell.appendchild(o); }
   row.appendchild(cell);
  });
  ofragment.appendchild(row);
 })
 //ie的table不支持innerhtml所以这样清空table
 while(filelist.haschildnodes()){ filelist.removechild(filelist.firstchild); }
 filelist.appendchild(ofragment);
}


$("idlimit").innerhtml = fu.limit;

$("idext").innerhtml = fu.extin.join(",");

$("idbtndel").onclick = function(){ fu.clear(); }

//在后台通过window.parent来访问主页面的函数
function finish(msg){ alert(msg); location.href = location.href; }

</script>
</body>
</html>

file.php文件

<?
$sort=12;
$f_type=strtolower("swf,jpg,rar,zip,7z,iso,gif");//设置可上传的文件类型
$file_size_max=200*1024*1024;//限制单个文件上传最大容量
$overwrite = 0;//是否允许覆盖相同文件,1:允许,0:不允许
$f_input="files";//设置上传域名称
    foreach($_files[$f_input]["error"] as $key => $error){
        $up_error="no";
        if ($error == upload_err_ok){
            $f_name=$_files[$f_input]['name'][$key];//获取上传源文件名
   $uploaddir ='./www.111cn.net/';
            $uploadfile=$uploaddir.strtolower(basename($f_name));
            
            $tmp_type=substr(strrchr($f_name,"."),1);//获取文件扩展名
   $tmp_type=strtolower($tmp_type);
            if(!stristr($f_type,$tmp_type)){
                echo "<script>alert('对不起,不能上传".$tmp_type."格式文件, ".$f_name." 文件上传失败!')</script>";
                $up_error="yes";
            }
            
            if ($_files[$f_input]['size'][$key]>$file_size_max) {
   
                echo "<script>alert('对不起,你上传的文件 ".$f_name." 容量为".round($_files[$f_input]
['size'][$key]/1024)."kb,大于规定的".($file_size_max/1024)."kb,上传失败!')</script>";
                $up_error="yes";
            }
            
            if (file_exists($uploadfile)&&!$overwrite){
                echo "<script>alert('对不起,文件 ".$f_name." 已经存在,上传失败!')</script>";
                $up_error="yes";
            }
             $string = 'abcdefghijklmnopgrstuvwxyz0123456789';
$rand = '';
for ($x=0;$x<12;$x++)
  $rand .= substr($string,mt_rand(0,strlen($string)-1),1);
$t=date("ymdhis").substr($gettime[0],2,6).$rand;
$attdir="./file/"; 
    if(!is_dir($attdir))  
    {  mkdir($attdir);}
            $uploadfile=$attdir.$t.".".$tmp_type;
            if(($up_error!="yes") and (move_uploaded_file($_files[$f_input]['tmp_name']

[$key], $uploadfile))){

                
    $_msg=$_msg.$f_name.'上传成功 ';
    
    
            }
   else{
   $_msg=$_msg.$f_name.'上传失败 ';
   }
        }
 
    }
echo "<script>window.parent.finish('".$_msg."');</script>"; 
?>

 代码如下 复制代码
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
<title></title>
<script language="网页特效" type="text/网页特效">
function addinput()//增加input节点
{
var input=document.createelement('input');//创建一个input节点
var br=document.createelement('br');//创建一个br节点
input.setattribute('type','file');// 设置input节点type属性为file
input.setattribute('name','files[]');//设置input节点 name属性为files[],以 数组的方式传递给服务器端
document.form1.appendchild(br);//把节点添加到 form1表单中
document.form1.appendchild(input);
}
</script>
</head>
<?php
if($_post['sub']=="www")
{
$waterimg="water.png";
$ftype=array('image/jpg','image/jpeg','imgage/png','image/pjpeg','image/gif');//允许上传的文件类型
$files=$_files['files'];
$fnum=count($files['name']); //取得上传文件个数
for($i=0;$i<$fnum;$i++)
{
 
   if($files['name'][$i]!=''&&is_uploaded_file($files['tmp_name'][$i]))
   {
  
    if(in_array($files['type'][$i],$ftype))//判断文件是否是允许的类型
    {
 
     $fname[$i]='upfile/'.rand(0,10000).time().substr($files['name'] [$i],strrpos($files['name'][$i],'.'));//自动命名
     move_uploaded_file($files['tmp_name'][$i],$fname[$i]);
     echo '<br/>文件上传成功!';
 
    }
    else
    {
     echo '<br/>不允许的文件类型!';
  exit;
    }
   }
   else
   {
    echo '<br/>该文件不存在!';
 exit;
   }
watermark($fname[$i],$waterimg);   
}
 
  $string=implode('|',$fname);
 echo $string;
}
 
?>
<body>
<form name="form1" method="post" action="" enctype="multipart/form-data" >
    <input type="file" name="files[]" id="files[]" />
<input type="submit" name="sub" value="上传"/>
<input name="sub" type="hidden" id="sub" value="www" />
</form>
<a href="#" onclick="addinput()">再上传一张</a>
<?
/**
* 为图片加水印
* @param string $desimg 目标图片 参数格式为 ./images/pic.jpg
* @param string $waterimg 水印图片 参数格式同上,水印图片为 png格式,背景透明
* @param int positon 水印地位 1:顶部居左 2:顶部居右 3:居中 4 :底部居左 5:底部居右
* @param bool $saveas 能否另存为,默许值false,默示笼盖原图
* @param int $alpha 水印图片的不通明度
* @return string $savepath 新图片的途径
* **/
function watermark($desimg,$waterimg,$positon=1,$saveas=false,$alpha=30)
{
//获取目图片的根基信息
$temp=pathinfo($desimg);
$name=$temp["basename"];//文件名
$path=$temp["dirname"];//文件地点的文件夹
$extension=$temp["extension"];//文件扩展名
if($saveas)
{
//需要另存为
$name=rtrim($name,".$extension")."_2.";//从头命名
$savepath=$path."/".$name.$extension;
}
else
{
//不需要另存为则笼盖原图
$savepath=$path."/".$name;
}
$info=getimageinfo($desimg);//获取目标图片的信息
$info2=getimageinfo($waterimg);//获取水印图片的信息
$desimg=create($desimg);//从原图创立
$waterimg=create($waterimg);//从水印图片创立
//地位1:顶部居左
if($positon==1)
{
$x=0;
$y=0;
}
//地位2:顶部居右
if($positon==2)
{
$x=$info[0]-$info2[0];
$y=0;
}
//地位3:居中
if($positon==3)
{
$x=($info[0]-$info2[0])/2;
$y=($info[1]-$info2[1])/2;
}
//地位4:底部居左
if($positon==4)
{
$x=0;
$y=$info[1]-$info2[1];
}
//地位5:底部居右
if($positon==5)
{
$x=$info[0]-$info2[0];
$y=$info[1]-$info2[1];
}
imagecopymerge($desimg,$waterimg,$x,$y,0,0,$info2[0],$info2[1],$alpha);
imagejpeg($desimg,$savepath);
imagedestroy($desimg);
imagedestroy($waterimg);
return $savepath;
}
/**
* 获取图片的信息,width,height,image/type
* @param string $src 图片途径
* @return 数组
* **/
function getimageinfo($src)
{
return getimagesize($src);
}
/**
* 创立图片,前往本钱范例
* @param string $src 图片途径
* @return resource $im 前往本钱范例
* **/
function create($src)
{
$info=getimageinfo($src);
switch ($info[2])
{
case 1:
$im=imagecreatefromgif($src);
break;
case 2:
$im=imagecreatefromjpeg($src);
break;
case 3:
$im=imagecreatefrompng($src);
break;
}
return $im;
}
 ?>

</body>
</html>

csv是常用的excel格式的替代品哦,很多时候我们导出数据是都会导成csv格式的,这样和excel没什么区别,下面的程序是要读取csv数据保存到数组我们要对数据进行操作,所以保存到数据。
 代码如下 复制代码

$info=csvtoarray::open('teste.csv');
//echo '<pre>';
//print_r($info);
//echo '</pre>';
foreach ($info as $c)
 {
  echo '学号:'.$c[0];
  echo '姓名:'.$c[1];
  echo '年龄:'.$c[2];
  echo '身高:'.$c[3].'<br>';
 }
 

 final class csvtoarray{

  /**
   * 把csv文件解析为一个数组返回
   *
   * @param string $file 要解析的csv文件路径
   * @param char $delimiter csv文件里的内容分隔符 默认为;
   * @return array
   */
  public static function open($file, $delimiter = ';'){
   return self::ordenamultiarray(self::csvarray($file, $delimiter), 1);
  }

  private function csvarray($file, $delimiter)
  {
   $result = array();
   $size = filesize($file) + 1;
   $file = fopen($file, 'r');
   $keys = fgetcsv($file, $size, $delimiter);
   fseek($file,0);//这里原来的没有..自己加上..这样能读取到第一行的内容
   while ($row = fgetcsv($file, $size, $delimiter))
   {
    for($i = 0; $i < count($row); $i++)
    {
     if(array_key_exists($i, $keys))
     {
      $row[$keys[$i]] = $row[$i];
     }
    }
    print_r($row);
    $result[] = $row;
   }

   fclose($file);

   return $result;
  }
  private function ordenamultiarray($multiarray, $secondindex)
  {
   while (list($firstindex, ) = each($multiarray))
   $indexmap[$firstindex] = $multiarray[$firstindex][$secondindex];
   asort($indexmap);
   while (list($firstindex, ) = each($indexmap))
   if (is_numeric($firstindex))
   $sortedarray[] = $multiarray[$firstindex];
   else $sortedarray[$firstindex] = $multiarray[$firstindex];
   return $sortedarray;
  }
 }

[!--infotagslink--]

相关文章

  • Php文件上传类class.upload.php用法示例

    本文章来人大家介绍一个php文件上传类的使用方法,期望此实例对各位php入门者会有不小帮助哦。 简介 Class.upload.php是用于管理上传文件的php文件上传类, 它可以帮...2016-11-25
  • PHP文件上传一些小收获

    又码了一个周末的代码,这次在做一些关于文件上传的东西。(PHP UPLOAD)小有收获项目是一个BT种子列表,用户有权限上传自己的种子,然后配合BT TRACK服务器把种子的信息写出来...2016-11-25
  • jQuery实现简单的文件上传进度条效果

    本文实例讲述了jQuery实现文件上传进度条效果的代码。分享给大家供大家参考。具体如下: 运行效果截图如下:具体代码如下:<!DOCTYPE html><html><head><meta charset="utf-8"><title>upload</title><link rel="stylesheet...2015-11-24
  • php文件上传你必须知道的几点

    本篇文章主要说明的是与php文件上传的相关配置的知识点。PHP文件上传功能配置主要涉及php.ini配置文件中的upload_tmp_dir、upload_max_filesize、post_max_size等选项,下面一一说明。打开php.ini配置文件找到File Upl...2015-10-21
  • 借助FileReader实现将文件编码为Base64后通过AJAX上传

    这篇文章主要介绍了借助FileReader实现将文件编码为Base64后通过AJAX上传的方法,包括后端对文件数据解码并保存的PHP代码,需要的朋友可以参考下...2015-12-25
  • jQuery+ajax简单实现文件上传的方法

    这篇文章主要介绍了jQuery+ajax简单实现文件上传的方法,结合实例形式简单分析了jQuery基于ajax的post方法进行文件传输及asp.net后台处理技巧,需要的朋友可以参考下...2016-06-12
  • js实现上传文件添加和删除文件选择框

    这篇文章主要为大家详细介绍了js实现上传文件添加和删除文件选择框 ,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2016-10-25
  • 适用于初学者的简易PHP文件上传类

    本文实例讲述了PHP多文件上传类,分享给大家供大家参考。具体如下:<&#63;phpclass Test_Upload{ protected $_uploaded = array(); protected $_destination; protected $_max = 1024000; protected $_messages =...2015-10-30
  • js 实现文件上传样式详情

    这篇文章主要介绍了js 实现文件上传样式,下面文章举例说明js 是如何实现文件上传样式的,附有代码详细解说,需要的朋友可以参考一下,希望对你有所帮助...2021-10-21
  • PHP利用APC模块实现大文件上传进度条的方法

    php 大文件带进度的上传,一直是一个令php程序员很苦恼的问题。查询baidu 、Google ,大体做带进度的上传方式为:flash+php,socket,apc+php等,下面我介绍了apc +php+ajax制作的带进度的上传,并贴出源码,希望对大家有用。 Altern...2015-10-30
  • C#文件上传的简单实现

    这篇文章主要为大家详细介绍了C#文件上传的简单实现,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-25
  • php需登录的文件上传管理系统

    本文给大家介绍一个不错的需要登录的php 文件上传管理系统,功能简单有需要了解的同学可参考。 代码如下<&#63;php$admin_pw="admin";//管理密码$uploaddir="upload";//上传目录session_start();if($_GET['action']=="g...2015-10-30
  • asp.net html控件的File控件实现多文件上传实例分享

    asp.net中html控件的File控件实现多文件上传简单实例,开发工具vs2010使用c#语言,感兴趣的朋友可以了解下,必定是多文件上传值得学习,或许本文所提供的知识点对你有所帮助...2021-09-22
  • TypeScript前端上传文件到MinIO示例详解

    这篇文章主要为大家介绍了TypeScript前端上传文件到MinIO示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪...2022-10-12
  • JQuery异步提交表单与文件上传功能示例

    这篇文章主要介绍了JQuery异步提交表单与文件上传功能,结合实例形式分析了jQuery表单提交及文件传输操作的相关实现技巧,需要的朋友可以参考下...2017-01-16
  • PHP文件上传主要代码讲解

    复制代码 代码如下:<?php if($_FILES['myfile']['name'] != '') { if($_FILES['myfile']['error'] > 0) { echo "错误状态:" . $_FILES['myfile']['error']; } else { move_uploaded_f...2013-10-04
  • 使用jQuery.form.js/springmvc框架实现文件上传功能

    这篇文章主要介绍了使用jQuery.form.jsspringmvc框架实现文件上传功能,非常具有参考借鉴价值,感兴趣的朋友一起学习吧...2016-05-14
  • jquery插件uploadify实现带进度条的文件批量上传

    这篇文章主要介绍了jquery插件uploadify实现带进度条的文件批量上传,感兴趣的小伙伴们可以参考一下...2015-12-14
  • C#简单实现文件上传功能

    这篇文章主要介绍了C#简单实现文件上传功能,利用MVC+EF+LigerUI 实现的upload上传功能,感兴趣的小伙伴们可以参考一下...2020-06-25
  • PHP的文件上传处理验证示例

    文件上传中有一块非常重要的就是安全验证了,如果验证不合理就很容易给一些人把此利用上传非常的黑客文件了,那么对于新学php新手文件上传验证有多了解呢?如果不懂可以看...2016-11-25