Php implements the cvs data import MySQL method based on the Fleaphp framework. fleaphpcvs_PHP tutorial

Source: Internet
Author: User
Php implements the cvs data import MySQL method based on the Fleaphp framework, fleaphpcvs. Php implements cvs data import to MySQL based on the Fleaphp framework. fleaphpcvs this article describes how php imports cvs data into MySQL based on the Fleaphp framework. I would like to share with you how php imports cvs data into MySQL based on the Fleaphp framework for your reference. fleaphpcvs

This example describes how php imports cvs data into MySQL based on the Fleaphp framework. We will share this with you for your reference. The details are 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 _ construct () {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") ;}// judge date private function isDate ($ file_name) {$ filename = explode ('. ', $ file_name); $ real_name = $ filename [count ($ filename)-2]; // get the file name $ format = "Y-m-d "; // Time format type $ unixTime = strtotime ($ real_name); $ checkDate = dat E ($ 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'] ['err Or ']; // Check if ($ file_name = null) {echo "file selection error. check whether the file is uploaded. "; Exit;} // Determine the file size if ($ file_size> = 10241024) {$ file_size = round ($ file_size/1048576*100)/100. 'MB '; print_r ("The size of the uploaded file is ". "$ file_size"); echo ": the system can only upload files smaller than 10 MB. "; Exit;} // $ extention_name = end (explode ('. ', $ _ FILES ["upload_file"] ['name']); // Obtain the extension $ extention_name = preg_replace ('/. */. (. * [^/.]. *) */iU ',' // 1', $ file_name); // Obtain the file extension. // check the file type if ($ file_type! = "Application/vnd. ms-excel" & $ extention_name! = "Csv") {echo "type of the file you uploaded:.", $ extention_name ,"
"; Print_r (" allowed file types :. csv "); exit;} if (file_exists ($ this-> uploaddir. $ _ FILES ['upload _ file'] ['name']) {print ("data with the same name in the backup directory exists"); // exit exists in the file ;} if ($ this-> isDate ($ file_name) = FALSE) {print ("the file name format is incorrect. the format is correct. Example: 2010-10-28.csv "); // The file has 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, 1000); // $ date = setOutputEncoding ('utf-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 to use strlen to determine whether the character length is equal to the character length. now, formatted output is directly used, and the original structure remains unchanged. {$ Attendance_time = sprintf ("% 02d", $ hours ). ":". sprintf ("% 02d", $ minutes);} else {$ attendance_time = sprintf ("% 02d", $ hours ). ":". sprintf ("% 02d", $ minutes) ;}// correct the non-attendance time, remove the on-duty time during lunch break if ($ attendance_time = ") {$ attendance_time = "00:00";} $ t ["ATTENDANCE_TIME"] = $ attendance_time; // save on-duty time $ attendance-> create ($ t ); // save to database} // print_r ("data imported successfully ")."
"; // Raw csv file data backup, the file is saved in the system's./uploadfiles/folder switch ($ file_error) {case 0: Echo" attendance data updated successfully "."
"; Break; case 1: Echo" the uploaded file exceeds the limit of the upload_max_filesize option 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" only part of the file is uploaded "."
"; Break; case 4: Echo" no file is uploaded "."
"; Break; case 6: Echo" temporary folder Not Found "."
"; Break; case 7: Echo" file writing 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 'success of original data backup ';} else {echo 'failed to back up raw data ';}}}?>

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.