<input type="file" id="uploadInput" style="display: none">
<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-info', plain:true" οnclick="uploadGoods()">选择表单</a>
<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true" οnclick="uploadDo()">上传</a>
// 上传重点药品
function uploadGoods() {
$('#uploadInput').click();
}
function uploadDo(){
var formData = new FormData();
formData.append("excelFile", document.getElementById("uploadInput").files[0]);
var pc=$("input[name='purchase_channels']").val();
formData.append("purchase_channels",pc);
var hp=$("#head_position").val();
formData.append("head_position",hp);
$.ajax({
url: "{:U('Price/doUpload')}",
type: "POST",
data: formData,
contentType: false, //必须false才会自动加上正确的Content-Type
processData: false, //必须false才会避开jQuery对 formdata 的默认处理
success: function (rsp) {
}
});
}
public function doUploadAction(){
$cust_id=session('cust_id');
$purchase_channels=$_POST['purchase_channels'];
$head_position=$_POST['head_position'];
$org_id=session("org_parent_id");
$file = $_FILES['excelFile'];
$ext = pathinfo($_FILES['excelFile']['name'], PATHINFO_EXTENSION);
if (!in_array($ext, array('xls','xlsx'))) {
$this->ajaxReturn(array('code'=>'-1','message'=>'上传格式错误'));
}
$up_file= $file['tmp_name'];
import("Org.Util.PHPExcel");
$objPHPExcel = \PHPExcel_IOFactory::load($up_file);
$objWorksheet = $objPHPExcel->getActiveSheet();
$array = $objWorksheet->toArray('', true, true, false);
if($file['name']){
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 3145728;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg','xls','xlsx');// 设置附件上传类型
$upload->rootPath = './Public/Uploads/'.$filename.'/'; // 设置附件上传根目录
$upload->savePath = ''; // 设置附件上传(子)目录
$info = $upload->upload();
$excel_path = '/'.$filename.'/' . $info['excelFile']['savepath'] . $info['excelFile']['savename'];
}
}