PHP Upload and process a CSV file -
I have an upload form that takes a CSV file. Then I process it with PHP.
& lt; Form action = "" method = "post" enctype = "multipart / form-data" & gt; & Lt; Input type = "file" name = "file" id = "file" /> & Lt; Br / & gt; & Lt; Input type = "submit" name = "submit" value = "sweep up!" Class = "upload_sub" /> & Lt; Br / & gt; & Lt; Br / & gt; & Lt; / Form & gt; & Lt ;? Php if (isset ($ _ POST ['submit'])} {if ($ _ files ["csv"] ["error"]> gt;} {echo 'echo' verse God forsoc igen. ';} And { $ Import = $ import = $ _FILES ['csv'] ['tmp_name']; $ Import = new importer (); $ import & gt; importTariff ($ tmp);}}? & Gt;
< P> lib.php class importer (I only submit related functions) public function importTariff ($ tmp) {if (($$ Handle = fopen ( $ Tmp, 'r')) == FALSE {while ($ data = fgetcsv ($ handle, 1000, ';'))! == FALSE {echo 'foo'; }}}
For testing purposes, I want to print 'Foo' for each line in CSV. Although I do not get any error or any such idea?
print_r ($ _ files);
View your NAME with file input:
& lt; Input type = "file" name = "file" id = "file" /> Change it to name = "csv"
or $ _ files ["csv"]
to $ _ FILES [" File "]
Comments
Post a Comment