假设我有一张桌子objects
:
CREATE TABLE objects (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
someinfo VARCHAR(255),
);
还有一个像这样的文本文件:
name,someinfo
"firstname","firstinfo"
"secondname","secondinfo"
...
如何在 CakePHP 中上传这个文本文件来处理数据和创建对象?处理不是问题,我已经解决了。但是,我不确定如何上传文件。
注意:文件最大为 300MB。
编辑
我尝试LOAD DATA INFILE
按照 dogmatic69 的建议使用,使用以下代码:
$filefullname = $this->request->data['File']['file']['tmp_name'];
debug($filefullname);
$query = 'LOAD DATA LOW_PRIORITY INFILE "'.$filefullname.'" INTO TABLE agencies FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r" IGNORE 1 LINES';
$this->Agency->query($query);
但是,我得到以下输出:
'C:\Windows\Temp\phpB413.tmp'
Error: SQLSTATE[HY000]: General error: 29 File 'C:\ProgramData\MySQL\MySQL Server 5.5\data\WindowsTempphpB413.tmp' not found (Errcode: 2)
SQL Query: LOAD DATA LOW_PRIORITY INFILE "C:\Windows\Temp\phpB413.tmp" INTO TABLE agencies FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r" IGNORE 1 LINES