将 dataURI 图像从 JavaScript 解析为 PHP
Parsing dataURI image from JavaScript to PHP
我在 JavaScript 中创建了一个函数,将用户选择的 'image' 文件转换为 dataURI。然后我通过 POST 方法将它传递给 php 脚本。问题是当我尝试将此信息保存到 MySQL 中时,如下所示
$him = $_POST["him"];
$req = $pdo->prepare("INSERT INTO `cr`.`chercheur`
(`cin`, `nom`, `prenom`, `statut`,
`tel1`, `email`, `tof`, `etat`)
VALUES (?, ?, ?, ?, ?,?, ?, '0')");
$req->execute(array($cin,$nom,$prenom,$statu,$tel,$mail,$him));
下面出现错误。
Warning: PDOStatement::execute(): MySQL server has gone away in
C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\CR\module\compte\demande\dem_user.php
on line 89
Warning: PDOStatement::execute(): Error reading result set's header in
C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\CR\module\compte\demande\dem_user.php
on line 89 SQLSTATE[HY000]: General error: 2006 MySQL server has gone
away
这可能是因为您尝试存储的图像大小足以溢出为 MySQL 配置的最大数据包大小。尝试将 MySQL 安装文件夹(在 [mysqld]
部分下)的 my.ini
中的 max_allowed_packet
设置更改为更大的值。
您可以使用以下 SQL 命令检查当前值(以及您设置的新值是否生效):
SHOW VARIABLES LIKE 'max_allowed_packet';
查看此页面:http://dev.mysql.com/doc/refman/5.0/en/gone-away.html
You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld receives a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection. If you need big queries (for example, if you are working with big BLOB columns), you can increase the query limit by setting the server's max_allowed_packet variable, which has a default value of 1MB. You may also need to increase the maximum packet size on the client end. More information on setting the packet size is given in Section B.5.2.10, “Packet Too Large”.
问题是 JavaScript 端的 dataURI 使用“+”进行连接,而 PHP 使用“.”所以解决方案是将“+”替换为“.”
我在 JavaScript 中创建了一个函数,将用户选择的 'image' 文件转换为 dataURI。然后我通过 POST 方法将它传递给 php 脚本。问题是当我尝试将此信息保存到 MySQL 中时,如下所示
$him = $_POST["him"];
$req = $pdo->prepare("INSERT INTO `cr`.`chercheur`
(`cin`, `nom`, `prenom`, `statut`,
`tel1`, `email`, `tof`, `etat`)
VALUES (?, ?, ?, ?, ?,?, ?, '0')");
$req->execute(array($cin,$nom,$prenom,$statu,$tel,$mail,$him));
下面出现错误。
Warning: PDOStatement::execute(): MySQL server has gone away in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\CR\module\compte\demande\dem_user.php on line 89
Warning: PDOStatement::execute(): Error reading result set's header in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\CR\module\compte\demande\dem_user.php on line 89 SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
这可能是因为您尝试存储的图像大小足以溢出为 MySQL 配置的最大数据包大小。尝试将 MySQL 安装文件夹(在 [mysqld]
部分下)的 my.ini
中的 max_allowed_packet
设置更改为更大的值。
您可以使用以下 SQL 命令检查当前值(以及您设置的新值是否生效):
SHOW VARIABLES LIKE 'max_allowed_packet';
查看此页面:http://dev.mysql.com/doc/refman/5.0/en/gone-away.html
You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld receives a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection. If you need big queries (for example, if you are working with big BLOB columns), you can increase the query limit by setting the server's max_allowed_packet variable, which has a default value of 1MB. You may also need to increase the maximum packet size on the client end. More information on setting the packet size is given in Section B.5.2.10, “Packet Too Large”.
问题是 JavaScript 端的 dataURI 使用“+”进行连接,而 PHP 使用“.”所以解决方案是将“+”替换为“.”