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/>?>