从php中获取ftp和process中的文件数据(fetch file data from ftp & process in php)
我有以下脚本从我的ftp服务器上的csv文件导入数据,该脚本正常工作。
$ftp_server = '---Domain---'; $ftp_user_name = '---Uname---'; $ftp_user_pass = '---pass---'; // open some file for reading $csvfile = '/home/domain/public_html/myfolder/user.csv'; if(!file_exists($csvfile)) { echo "File not found. Make sure you specified the correct path.\n"; exit; } else { echo "File exist on this path.\n"; }user.csv
Email Fname lname ------------------------------ mark@gmail.com mark martin allan@gmail.com allan lee我想从csv文件中获取数据并传递给php函数,该函数将使用DB处理该数据
即添加更新用户信息
我没有得到如何获取数据和传递给函数
任何帮助将不胜感激。
谢谢。
I have the below script to import data from a csv file on my ftp server, the script works correctly.
$ftp_server = '---Domain---'; $ftp_user_name = '---Uname---'; $ftp_user_pass = '---pass---'; // open some file for reading $csvfile = '/home/domain/public_html/myfolder/user.csv'; if(!file_exists($csvfile)) { echo "File not found. Make sure you specified the correct path.\n"; exit; } else { echo "File exist on this path.\n"; }user.csv
Email Fname lname ------------------------------ mark@gmail.com mark martin allan@gmail.com allan leeI want to fetch data from csv file & pass to php function which will process that data with DB
i.e. add-update user information
I am not getting how to fetch data & pass to function
Any assistance will be appreciated.
Thanks.
最满意答案
$a=array(); $file = fopen('user.csv', 'r'); while (($line = fgetcsv($file)) !== FALSE) { array_push($a,$line); } fclose($file);//你将获得数组$ a中的所有内容,你可以使用foreach来运行数组
$a=array(); $file = fopen('user.csv', 'r'); while (($line = fgetcsv($file)) !== FALSE) { array_push($a,$line); } fclose($file);//you will get all the content in array $a, you can ride array by using foreach
更多推荐
发布评论