Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将图像插入mysql_Php_Mysql_Forms - Fatal编程技术网

Php 如何将图像插入mysql

Php 如何将图像插入mysql,php,mysql,forms,Php,Mysql,Forms,我正试图上传4个图像到我的文件目录,而且我想把它们的参考保存在数据库中。但在我下面的当前代码中,它所做的是在数据库中插入另一行,而不是将图像1放入img1,以此类推 我已经放弃了。我不知道我做错了什么 试试这个: 在循环中: $currently_item[] = current($_FILES['file_array']['name']); 出局 $currently_item = current($_FILES['file_array']['name']);

我正试图上传4个图像到我的文件目录,而且我想把它们的参考保存在数据库中。但在我下面的当前代码中,它所做的是在数据库中插入另一行,而不是将图像1放入img1,以此类推

我已经放弃了。我不知道我做错了什么










试试这个:

在循环中:

 $currently_item[] = current($_FILES['file_array']['name']);
出局

   $currently_item = current($_FILES['file_array']['name']);

    $sql = $conn[![enter image description here][1]][1]->query("INSERT INTO posts(img1, img2, img3) 
   Values('".$currently_item[0]."','".$currently_item[1]."','".$currently_item[2]."')");

请执行验证检查,例如值是否存在。

尝试使用“加载文件”功能传递文件。它以字符串形式返回文件内容,您可以在INSERT或UPDATE命令中使用该字符串-

INSERT INTO table(id, file_name, file_data) VALUES(1, 'img.png', LOAD_FILE('img.png'));
功能。

阅读本教程:以及:
INSERT INTO table(id, file_name, file_data) VALUES(1, 'img.png', LOAD_FILE('img.png'));