Load and read a csv file with php

半城伤御伤魂 提交于 2019-11-27 06:28:52

问题


I want to download some content in csv format. It is stored online in a csv file. I can not just read the content. I first have to download the file, open and then read it.

Is there a way to open it directly? Or do I have to first load/upload it on my server and then open it like a classic file?


回答1:


Yes, it can open directly using fopen and fgetcsv

However, this feature sometime is restricted for security concern, and you can read the details via the documentation

  • http://php.net/manual/en/function.fopen.php
  • http://php.net/manual/en/function.fgetcsv.php

Another drawback of open directly, if the page is processed many time, which mean it generate lots of network transfer overhead, and potentially slow down your page generation time.

Ideal case will be download into your server, and repeated use local disk file for processing, that will save some network bandwidth.




回答2:


Check out fgetcsv() and str_getcsv()



来源:https://stackoverflow.com/questions/4354517/load-and-read-a-csv-file-with-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!