> $filename=$_FILES["userfile"]["tmp_name"]; > > That one line is not working as expected, which means that the rest of your code will fail. Html form extract: <form enctype="multipart/form-data" action="...php" method='post'> <input type="hidden" name="MAX_FILE_SIZE" value="50" /> <p> Select file on your computer: <input name="userfile" type="file" /> <input type="submit" name='datacsvimport' value=" data file" /> </p> </form>