PHP-based fleaphp framework for the implementation of CVS data import MySQL method, fleaphpcvs_php tutorial

Source: Internet
Author: User
Tags mysql text sprintf

PHP based on the fleaphp framework to implement the CVS data import MySQL method, Fleaphpcvs


This paper introduces the method of PHP data import into MySQL based on fleaphp framework. Share to everyone for your reference, as follows:

<?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 _cons Truct () {parent::__construct ();}  $patch = "http://localhost/uploadfiles";/function Actionindex () {$smarty =& $this->_getview (); $smarty->display ("kaoqin_upload.html");  }//Display error private Function Showerro () {error_reporting (E_all); Ini_set ("Display_errors", "on"); }//Judgment date Private function isDate ($file _name) {$filename = explode ('. ', $file _name); $real _name = $filename [Count ($filenam  e) -2];//Get the file name $format = "y-m-d";//Time format type $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 ']; Check the file if ($file _name==null) {echo ' File selection error, please check the upload file.    ";   Exit }//Determine file size if ($file _size >=10241024) {$file _size = round ($file _size/1048576 * 100)/100.    ' MB '; Print_r ("uploaded file size is". ")  $file _size "); echo "System only allows uploading files within 10M size.  ";   Exit }//$extention _name = end (Explode ('. ', $_files["Upload_file" [' Name ']));//Get extension $extention _name=preg_replace ('/.*/. *[^/.]. *) */iu ', '//1 ', $file _name);//Get the file extension//Check file type if ($file _type!= "application/vnd.ms-excel" && $extention _name ! = "CSV") {echo "The file type you uploaded:.", $extention _name, "
"; Print_r ("System allowed file type:. csv"); Exit } if (file_exists ($this->uploaddir.$_files[' upload_file ' [' name ']) {print ("Backup directory with the same name data exists");//file exists exit; } if ($this->isdate ($file _name) ==false) {print ("The file name is not well-formed, the format is correct. Example: 2010-10-28.csv "); File exists exit; }//Var_dump (file_exists ($this->uploaddir.$_files[' upload_file ' [' name '])); Test returns Print_r ("Original Attendance data file:". $_files[' upload_file ' [' Name ']. "
"."
"); Data import//$fp = fopen ($_files[' upload_file ' [' Tmp_name '], "R"),//$data = Fgets ($fp, +);//$date =setoutputencoding (' u Tf-8 '); $data =file ($_files[' upload_file ' [' tmp_name ']); $attendance =& Get_singleton (' model_attendance '); Print_r ($data); Data import processing for ($i =1; $i =10 && $minutes <60)//start using strlen to determine the length of the character, and now directly with the formatted output, the original structure is unchanged. {$attendance _time = sprintf ("%02d", $hours). ":". sprintf ("%02d", $minutes);} else {$attendance _time = sprintf ("%02d", $hours). ":". sprintf ("%02d", $minutes); }}//Correct the absence of attendance time, remove the time during lunch break if ($attendance _time== " -1:00") {$attendance _time= "00:00"; } $t ["Attendance_time"]= $attendance _time;//saved in time $attendance->create ($t);//Deposit Database}//print_r ("Data import succeeded"). "
"; Raw CSV file data backup, file saved in the system./uploadfiles/folder under switch ($file _error) {case 0:echo "absence data updated successfully". "
"; Break Case 1:echo "The uploaded file exceeds the value of the Upload_max_filesize option limit in php.ini.". "
"; Break Case 2:echo "The size of the uploaded file exceeds the value specified by the Max_file_size option in the HTML form. "."
"; Break Case 3:echo "files are only partially uploaded".
"; break; Case 4:echo "No files were uploaded". "
"; break; Case 6:echo "temporary folder not found". "
"; break; Case 7:echo "File write Failed". "
"; break; } echo "
";//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 ' Raw data backup succeeded '; } else {echo ' failed to back up raw data '; }}}}?>

More readers interested in PHP related content can view the topic: "PHP Primer for Object-oriented programming", "PHP String Usage Summary", "Php+mysql Database Operations Primer" and "PHP common database Operation Skills Summary"

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • Fleaphp Rolesnamefield Bug Resolution method
    • How to use the Find function of fleaphp crud operation
    • How to use the Findbyfield function of fleaphp crud operation
    • fleaphp methods of pager used in the common method of paging
    • Fleaphp Method of security setting
    • A clever solution to the uncertain multi-condition query under fleaphp
    • An example of how PHP handles Excel CVS tables
    • How to import Excel files into MySQL database by PHP
    • PHP export MySQL data to Excel file (fputcsv)
    • Php method for importing Excel to MySQL
    • phpMyAdmin to import data from Excel into MySQL text method
    • PHP imports Excel into MySQL

http://www.bkjia.com/PHPjc/1102462.html www.bkjia.com true http://www.bkjia.com/PHPjc/1102462.html techarticle PHP based on the fleaphp framework to implement the CVS data import MySQL method, Fleaphpcvs This article describes PHP based on the fleaphp framework to implement the CVS data import MySQL method. Share to everyone for your reference ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.