Reputation: 4349
Is fgetcsv better than str_getcsv?
Upvotes: 7
Views: 8707
Reputation: 490233
Is
fgetcsv()
better thanstr_getcsv()
?
Yes, when opening from a file. Use str_getcsv()
only when you have the CSV already as a string in your program.
Is there a way to only allow
.csv
file types to be displayed in the file upload dialog?
No, unless you use a Flash wrapper. However, you can detect the file extension with JavaScript, and you must accept only .csv
with PHP (use pathinfo($filename, PATHINFO_EXTENSION)
).
However, ensuring it has .csv
does not confirm it is actually a CSV file.
Should I/do I need to use
ini_set('auto_detect_line_endings', true);
No, unless it is not working. The docs state there is a small performance penalty in using it. So only use it when it is required. It is also off by default. Best to leave less common things in php.ini
to their default, I have found.
Though make sure magic_quotes
and register_globals
are always off :)
Upvotes: 12