PHP import CSV

Source: Internet
Author: User

Import.html

 

<Form enctype = "multipart/form-Data" Action = "import. PHP "method =" Post "> <br/> Import template <br/> <label for =" file selection "> file selection: </label> <input name = "csv_goods" type = "file"/> <br/> <input type = "Submit" value = "import" name = "import "/> <br/> </form>

 

Import. php

 

<? Php <br/> If (isset ($ _ post ['import']) {<br/> $ file = $ _ FILES ['csv _ goods ']; <br/> $ file_type = substr (strstr ($ file ['name'], '. '), 1); <br/> // check the file format <br/> if ($ file_type! = 'Csv') {<br/> echo 'file format is incorrect. please upload it again! '; <Br/> exit; <br/>}< br/> $ handle = fopen ($ file ['tmp _ name'], "R "); <br/> $ file_encoding = mb_detect_encoding ($ handle); <br/> // check the file encoding <br/> if ($ file_encoding! = 'Ascii ') {<br/> echo' file Encoding Error. please upload it again! '; <Br/> exit; <br/>}< br/> $ ROW = 0; <br/> while ($ DATA = fgetcsv ($ handle, 1000 ,', ') {<br/> // you can know the total number of rows <br/> // echo "<font color = Red> $ row </font> "; <br/> $ row ++; <br/> if ($ ROW = 1) <br/> continue; <br/> $ num = count ($ data ); <br/> // The data of each cell in each row is output in sequence. <br/> for ($ I = 0; $ I <$ num; $ I ++) {<br/> echo $ data [$ I]. "<br>"; <br/> // process data here <br/>}< br/> fclose ($ handle ); <br/>}< br/>?>

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.