Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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中存储来自表单的预加载图像_Mysql_Image_Binary Data - Fatal编程技术网

如何使用PHP在mySQL中存储来自表单的预加载图像

如何使用PHP在mySQL中存储来自表单的预加载图像,mysql,image,binary-data,Mysql,Image,Binary Data,我需要在MySQL数据库中的blob文件中存储一个以表单形式预加载的图像 以下是表格代码: <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>Imag

我需要在MySQL数据库中的blob文件中存储一个以表单形式预加载的图像

以下是表格代码:

<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Image Name</td>
      <td><input type="text" name="imgName" id="imgName" /></td>
    </tr>
    <tr>
      <td>Image</td>
      <td><input type="image" name="myImg" id="myImg" src="images/1209894_11404408.jpg" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" align="center" valign="middle"><input type="submit" name="Submit" id="Submit" value="Submit" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
我使用的Inser查询是:

INSERT INTO img (img_name, img_img) VALUES ('$_POST['imgName']', '$_POST['myImg']')
短暂性脑缺血发作


Yogi Yang

首先,您需要设置html表单以支持文件上传,正确的表单标签将是:

<form enctype="multipart/form-data" id="form1" name="form1" action="<?php echo $editFormAction; ?>" method="post">
当然,首先需要打开MySQL连接,完成后关闭它

希望能有帮助


亲切的问候

我终于找到了解决办法

下面是我用来将图像正确保存到MySQL的代码

INSERT INTO img (img_name, img_img) VALUES ('$_POST['imgName']', base64_decode(substr('$_POST['myImg']', 22)));
同样,如果我们想将文件保存到服务器,我们可以在PHP中使用以下代码

$myid = fopen($filesavepath.$imgfilename,'wb');
$svgimg=$_REQUEST['svgimg'];
fputs($myid, base64_decode(substr($_POST['myImg'], 22)));
fclose($myid);
希望这对别人有帮助


Yogi Yang

如果您阅读了我的原始帖子,我特别说过图像是以input control()中的形式预加载的,因此不存在将图像文件上载到服务器的问题。我知道,因为网上有很多解决方案显示了你在这里建议的方法。但我的要求却大不相同。让我重新表述一下我的要求。我想将加载在输入文件中的图像(类型为“image”)保存到一个文件中。所以我想将浏览器中显示的图像内容保存到服务器上的文件中。谢谢。
INSERT INTO img (img_name, img_img) VALUES ('$_POST['imgName']', base64_decode(substr('$_POST['myImg']', 22)));
$myid = fopen($filesavepath.$imgfilename,'wb');
$svgimg=$_REQUEST['svgimg'];
fputs($myid, base64_decode(substr($_POST['myImg'], 22)));
fclose($myid);