function process_user_report($uid) { global $config; $mail = load_user_email($uid); if (!$mail) { return FALSE; } $sheets = $config['sheets']; foreach ($sheets as $index => $sheet) { if (empty($sheet)) { continue; } $sql = $sheet['sql']; $sql .= " WHERE product_apply.uid = " . $uid; $columns = $sheet['columns']; $name = $sheet['name']; $headers = array_values($columns); //初始化excel对象 $excel = init_excel(); //设置Excel第一行 init_excel_header($excel, $headers); $result = mysql_query($sql); if (!$result) { die("MYSQL error" . mysql_error()); } $crt_index = 1; while ($row = mysql_fetch_assoc($result)) { $data = array(); foreach ($columns as $column_name => $column) { $column_value = $row[$column_name]; if (!$column_value) { $column_value = "无信息记录"; } if (function_exists('process_' . $column_name)) { $column_value = call_user_func('process_' . $column_name, $column_value); } $data[] = $column_value; } excel_write_one_row($excel, $data, $crt_index); $crt_index += 1; } excel_rename_sheet($excel, $index, $name); $path = save_excel($excel, 'product_apply' . $uid); //$to = '*****@*****.**'; $to = '*****@*****.**'; $from = '*****@*****.**'; $message = "您好,\n附件是您在Masterprint 系统下印刷产品的使用统计数据.\n谢谢\n"; mail_attachment($to, '产品的印刷统计数据', wordwrap($message), $from, $path); } }
<div class="panel-heading"> <h3>Upload Locations</h3> </div> <div class="panel-body"> <?php $city = ""; $cityId = ""; $locations = array(); $duplicateLoc = false; if (isset($_FILES["locationExcel"])) { new_excel_upload(); } else { if (isset($_POST["save_excel"])) { save_excel($_POST["save_excel"]); } } function new_excel_upload() { global $locations; global $duplicateLoc; global $city; $date_obj = new DateTime(); $datetime = $date_obj->format('Ymd_his'); $target_dir = "excel_upload/"; $target_file = $target_dir . "Locations_" . $datetime . ".xls"; if (move_uploaded_file($_FILES["locationExcel"]["tmp_name"], $target_file)) { //echo "File is valid, and was successfully uploaded.\n"; } else { echo "File upload was not successfull, please try again\n";