dourong4031 2016-06-29 03:14
浏览 32

php上传csv文件,阅读它然后创建文件

I am uploading a csv file with this code:

$_ferror = $_FILES['file']['error'];
$_fsize = $_FILES['file']['size'];
$move = move_uploaded_file($_FILES['file']['tmp_name'], $_fpath."/" . $url);

where $_fpath contains the path to the directory where I want the files stored and the $url contains the file,name: "$url = $_FILES['file']['name'];"

my question is, how can I open the file, before I move it... I want to read from it and take the data in it, and then create 3 files from the one...

Based upon data I find in it.

Say I want these three files:

currentdate-type1.csv currentdate-type2.csv currentdate-type3.csv

Say the csv has these fields:

name,phone,type,email,address1,address2,city,state,zip,country

then I open it, find the "type" and if the type is, say, good, then put that whole line in a file I name currentdate-type1.csv, then if the type is great, put that in currentdate-type2.csv and if the type is awesome I put those lines in currentdate-type3.csv...

I guess, I could have it where the original file is the type1, then I just pull out those for type2 and type3....

Those are just examples, not really what I am wanting to do. I just cannot figure out how to start.

I want to start by reading the file... getting the first line, into an array of all the field names, so I can check which one is the field I want to get the data from in the data-rows....

Can you tell me how to open that file to read from it, getting the first line... for the fieldnames?

I would really appreciate tips, or where to find that on php training pages.

Thank you so very much in advance for any tips and/or pointing me to where I can learn that specifically how to...

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题