Table of Contents
php implements the method of importing cvs data into MySQL based on the Fleaphp framework, fleaphpcvs
Articles you may be interested in:
Home Backend Development PHP Tutorial PHP implements the method of importing cvs data into MySQL based on the Fleaphp framework, fleaphpcvs_PHP tutorial

PHP implements the method of importing cvs data into MySQL based on the Fleaphp framework, fleaphpcvs_PHP tutorial

Jul 12, 2016 am 08:58 AM
mysql php

php implements the method of importing cvs data into MySQL based on the Fleaphp framework, fleaphpcvs

This article describes the method of php based on the Fleaphp framework to implement the method of importing cvs data into MySQL. Share it with everyone for your reference, the details are as follows:

<&#63;php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Controller_KaoqinUpload extends FLEA_Controller_Action {
 var $uploaddir = "./uploadfiles/";
 public function _construct(){
  parent::__construct();
 }
// $patch="http://localhost/uploadfiles";/
 function actionIndex() {
  $smarty =& $this->_getView();
  $smarty->display("kaoqin_upload.html");
 }
 //显示错误
 private function showErro(){
 error_reporting(E_ALL);
  ini_set("display_errors","On");
 }
 //判断日期
 private function isDate($file_name)
 {
  $filename = explode('.',$file_name);
 $real_name = $filename[count($filename)-2];//得到文件名
  $format="Y-m-d";//时间格式类型
  $unixTime=strtotime($real_name);
  $checkDate= date($format,$unixTime);
   if($real_name==$checkDate)
    return ture;
   else
    return false;
 }
 public function actionSave(){
// $this->showErro();
 $upload_file=$_FILES['upload_file'];
 $file_name = $_FILES['upload_file']['name'];
 $file_tmp_name = $_FILES['upload_file']['tmp_name'];
 $file_type = $_FILES['upload_file']['type'];
 $file_size = $_FILES['upload_file']['size'];
 $file_error = $_FILES['upload_file']['error'];
  //检查文件
  if ($file_name==null)
   {
    echo "文件选择出错,请检查上传文件。";
    exit;
   }
  //判断文件大小
  if ($file_size >=10241024 )
   {
    $file_size = round($file_size/ 1048576 * 100) / 100 . ' mb';
    print_r("上传的文件大小为"."$file_size");
  echo "系统只允许上传大小为10M以内的文件。";
  exit;
   }
  //$extention_name = end(explode('.',$_FILES["upload_file"]['name']));//获取扩展名
  $extention_name=preg_replace('/.*/.(.*[^/.].*)*/iU','//1',$file_name);//获得文件的扩展名
  //检查文件类型
  if($file_type!="application/vnd.ms-excel"&& $extention_name!="csv")
   {
  echo "您上传的文件类型: .",$extention_name,"<br>";
  print_r("系统允许文件类型: .csv");
  exit;
   }
  if(file_exists($this->uploaddir.$_FILES['upload_file']['name']))
  {
    print("备份目录同名数据存在"); //文件存在
    exit;
  }
  if($this->isDate($file_name)==FALSE)
  {
    print("文件命名格式不对,正确格式。例:2010-10-28.csv");   //文件存在
    exit;
  }
  // var_dump(file_exists($this->uploaddir.$_FILES['upload_file']['name'])); //test返回
  print_r("原始考勤数据文件:".$_FILES['upload_file']['name']."<br>"."<br>");
  //数据导入
//  $fp = fopen($_FILES['upload_file']['tmp_name'], "r");
//  $data = fgets($fp, 1000);
//  $date=setOutputEncoding('utf-8');
  $data=file($_FILES['upload_file']['tmp_name']);
 $attendance =& get_singleton('Model_attendance');
  //print_r($data);
  //数据导入处理
  for($i=1;$i<count($data)-1;$i++) {
   $a=explode(";",$data[$i]);
   //编码格式转换
   $a[0]=iconv("gb2312", "utf-8", $a[0]);
   $a[1]=iconv("gb2312", "utf-8", $a[1]);
   $a[2]=iconv("gb2312", "utf-8", $a[2]);
   $a[4]=iconv("gb2312", "utf-8", $a[4]);
   $a[5]=iconv("gb2312", "utf-8", $a[5]);
   // print_r($a);
   $t=array();
   $t["ATTENDANCE_FINGERPRINT_ID"]=intval(trim($a[0],"/""));
   $t["ATTENDANCE_USER_NAME"]=trim($a[1],"/"");
   $t["ATTENDANCE_DATE"]=trim($a[2],"/"");
   // $t["ATTENDANCE_DIVISIONS"]=trim($a[3],"/"");//表中字段ATTENDANCE_DIVISIONS在表中删除
   $t["ATTENDANCE_GO_WORK"]=trim($a[4],"/"");
   $t["ATTENDANCE_AFTER_WORK"]=trim($a[5],"/"");
   //判断打卡情况
   $go_work = trim($a[4],"/"");//上班时间
   $after_work = trim($a[5],"/"");//下班时间
 //   print_r(var_dump($go_work));
   // exit();
   if(strlen($go_work)==0 && strlen($after_work)!=0)
    {
     $t["ATTENDANCE_STATUS"]= "1"; //"1"代表正常出勤
    }
   if(strlen($go_work)!=0 && strlen($after_work)==0)
    {
      $t["ATTENDANCE_STATUS"] ="2"; //"2"代表上班为打卡
    }
   if(strlen($go_work)!=0 && strlen($after_work)!=0)
    {
     $t["ATTENDANCE_STATUS"] ="3"; //"3"代表下班未打
    }
   if(strlen($go_work)==0 && strlen($after_work)==0)
    {
     $t["ATTENDANCE_STATUS"]= "4"; //"4"代表未出勤
    }
   //按考勤规则重置正常上下班时间
    if(strlen($go_work) == 0 && strlen($after_work) == 0)
   {
    $go_work = "24:00";
    $after_work = "00:00";//未出勤按子时计算
   }
   if(strlen($go_work) == 0 && strlen($after_work)!=0)
   {
    $t["ATTENDANCE_GO_WORK"] = $go_work = "08:35";//上班未打卡按08:35开始计算
   }
   if(strlen($go_work) != 0 && strlen($after_work) == 0)
   {
    $t["ATTENDANCE_AFTER_WORK"] = $after_work = "17:30"; //下班为打卡按17:30计算
   }
   //计算在勤时间
   $minutes;//保存分钟段
   $hours;//保存小时段
   $real_time1 = explode(":",$go_work);//上班时间分割数组
   $real_time2 = explode(":",$after_work);//下班时间分割数组
   //开始处理在勤时间
   $minutes=intval(intval($real_time2[1])-intval($real_time1[1]));
    if($minutes<0)
     {
     $hours=intval(intval(($real_time2[0])-1)-intval($real_time1[0]));
     if($hours<=0)
     {
      $hours=intval((intval($real_time2[0])-1)-intval($real_time1[0])+24);
      }
     $minutes=intval(intval($real_time2[1])+60-intval($real_time1[1]));
     $attendance_time = sprintf("%02d", $hours).":".sprintf("%02d", $minutes);
     }
    else
     {
     $hours =intval(intval($real_time2[0])-intval($real_time1[0]));
     if($hours<=0)
     {
      $hours = intval(intval($real_time2[0])-intval($real_time1[0])+24);
     }
     if($minutes>=10 && $minutes<60) //开始选用strlen判断字符长度补齐位,现在直接用格式化输出,原结构不变。
     {$attendance_time = sprintf("%02d", $hours).":".sprintf("%02d", $minutes);}
     else
     {
      $attendance_time = sprintf("%02d", $hours).":".sprintf("%02d", $minutes);
     }
     }
    // 更正未出勤时间情况,去除午休时间的在勤时间
    if($attendance_time=="-1:00")
    {
     $attendance_time="00:00";
    }
   $t["ATTENDANCE_TIME"]=$attendance_time;//保存在勤时间
   $attendance->create($t);//存入数据库
  }
//  print_r("数据导入成功")."<br>";
  //原始csv文件数据备份,文件保存在系统的./uploadfiles/文件夹下
  switch ($file_error)
  {
  case 0:
   Echo "考勤数据更新成功"."<br>"; break;
  case 1:
   Echo "上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值."."<br>"; break;
  case 2:
   Echo "上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值。"."<br>"; break;
  case 3:
   Echo "文件只有部分被上传"."<br>";break;
  case 4:
   Echo "没有文件被上传"."<br>";break;
  case 6:
   Echo "找不到临时文件夹"."<br>";break;
  case 7:
   Echo "文件写入失败"."<br>";break;
  }
  echo "<br>";
//  exit();
//  $absolutdir=$_SERVER[DOCUMENT_ROOT ].$uploaddir.$file_name;
  if ($_FILES["upload_file"]['error']==0)
  { //echo $file_tmp_name;
   //echo $this->uploaddir.$_FILES['upload_file']['name'];
   //$name=time();
   if( move_uploaded_file($file_tmp_name, $this->uploaddir.$_FILES['upload_file']['name']))
    {
    echo '原始数据备份成功';
     }
   else
    {
    echo '备份原始数据失败';
    }
  }
 }
}
&#63;>

Copy after login

Readers who are interested in more PHP related content can check out the special topics of this site: "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php mysql database operation introductory tutorial" Summary of common database operation skills in PHP》

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • Fleaphp rolesNameField bug solution
  • How to use the find function of fleaphp crud operation
  • fleaphp crud operation of findByField How to use functions
  • Common methods of paging in fleaphp How to use Pager
  • Security setting method of FleaPHP
  • Ingenious solution to uncertain multi-condition query under fleaphp
  • Example introduction of PHP's method of processing excel cvs table
  • How to import excel file into mysql database through PHP
  • PHP export MySQL data to Excel file (fputcsv)
  • PHP How to import Excel into MySQL
  • Graphic method of importing data from Excel into MySql under phpMyAdmin
  • php Import excel into mysql

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1102462.htmlTechArticlephp implements the method of importing cvs data into MySQL based on the Fleaphp framework, fleaphpcvs This article describes how PHP implements cvs data based on the Fleaphp framework How to import MySQL. Share it with everyone for your reference...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

PHP's Current Status: A Look at Web Development Trends PHP's Current Status: A Look at Web Development Trends Apr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

PHP: The Foundation of Many Websites PHP: The Foundation of Many Websites Apr 13, 2025 am 12:07 AM

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

See all articles