从php中获取ftp和process中的文件数据(fetch file data from ftp & process in php)

编程入门 行业动态 更新时间:2024-10-25 12:27:32
从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 lee

I 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

更多推荐

本文发布于:2023-07-05 14:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1038468.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   数据   process   php   ftp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!