gpt4 book ai didi

php - 在查询中找不到上传的 tmp 文件

转载 作者:行者123 更新时间:2023-11-29 14:06:56 27 4
gpt4 key购买 nike

我对 php 和 CakePHP 相当陌生,我尝试在上传文本文件 (2kb) 后执行以下代码:

$filefullname = $this->request->data['File']['file']['tmp_name'];
debug($filefullname);
move_uploaded_file($filefullname, WWW_ROOT.'tmp.txt');
$query = 'LOAD DATA LOW_PRIORITY INFILE "'.WWW_ROOT.'tmp.txt'.'" INTO TABLE agencies FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r" IGNORE 1 LINES';
debug($query);
$this->Agency->query($query);

虽然可以找到该文件,但我得到以下输出:

'C:\Windows\Temp\phpB413.tmp'
'LOAD DATA LOW_PRIORITY INFILE "C:\Data\myphpapplication\app\webroot\tmp.txt" INTO TABLE agencies FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r" IGNORE 1 LINES'
Error: SQLSTATE[HY000]: General error: 29 File 'C:\Data\myphpapplication\app\webroot\tmp.txt' not found (Errcode: 13)
SQL Query: LOAD DATA LOW_PRIORITY INFILE "C:\Data\myphpapplication\app\webroot\tmp.txt" INTO TABLE agencies FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r" IGNORE 1 LINES

我该如何解决这个问题?

最佳答案

很可能该文件就在那里,但 MySQL 不允许您从该位置读取文件。 MySQL 对读取 LOAD DATA ... INFILE 的位置有相当的限制,这是有充分理由的。您可能需要首先将文件移动到 MySQL 可以读取的路径,或者更改 MySQL 服务器的设置。

来自 MySQL 5.1 手册:

Note that, in the non-LOCAL case, these rules mean that a file named as ./myfile.txt is read from the server's data directory, whereas the file named as myfile.txt is read from the database directory of the default database. [...]

还有:

Windows path names are specified using forward slashes rather than backslashes. If you do use backslashes, you must double them.

关于php - 在查询中找不到上传的 tmp 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14203203/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com