Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.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将XML中的图像存储为MySql上的BLOB类型_Php_Mysql_Xml_Xml Parsing_Image Uploading - Fatal编程技术网

如何通过PHP将XML中的图像存储为MySql上的BLOB类型

如何通过PHP将XML中的图像存储为MySql上的BLOB类型,php,mysql,xml,xml-parsing,image-uploading,Php,Mysql,Xml,Xml Parsing,Image Uploading,我有一个XML文件,其中的图像数据如下 <vehicle_data> <vehicles> <vehicle> <brand>BMW</brand> <media> <images> <image> <local>D14591069439.JPG</loca

我有一个XML文件,其中的图像数据如下

  <vehicle_data>
    <vehicles>
      <vehicle>
        <brand>BMW</brand>
        <media>
          <images>
            <image>
              <local>D14591069439.JPG</local>
              <position>1</position>
            </image>
            <image>
              <local>D14591069447.JPG</local>
              <position>2</position>
            </image>
          </images>
        </media>
      </vehicle>
    </vehicles>
  </vehicle_data>
所有图像位置都位于放置XML文件的同一位置

现在我必须在mysql上将这些图像保存为BLOB类型

$info = mysqli_real_escape_string($con,file_get_contents($data->vehicle[$i]->media->images->image->local));

//$info = mysqli_real_escape_string($con,file_get_contents($_FILES['file']['tmp_name']));

$insert_media = 'insert into images (image) values ("'.$info.'")';

$media_qry = mysqli_query($con,$insert_media);
$last_media_id = mysqli_insert_id($con);
在上面的代码中,注释中的行

$info = mysqli_real_escape_string($con,file_get_contents($_FILES['file']['tmp_name']));
如果我上传一个文件并将其保存为mysql中的BLOB类型,这实际上是可行的

但在我的场景中,我只有一个文件名+扩展名“D14591069439.JPG”。哪个是字符串

需要帮助


提前感谢您的合作。

您尝试加载的文件必须位于特定目录中,因此请使用目录名+文件名来加载文件。了解防止sql注入的准备语句。@Jens建议,您的代码不安全且易受攻击。现在解决您的问题,您是否能够正确地记录
$data
变量?“它的形式正确吗?”詹斯谢谢,但我知道如何准备报表。现在我想要一种上传图像文件的方法,这个文件的名字是用XML写的。@Rohit刚才我已经更新了相同的命名变量。。。对不起。。。你能再查一下吗!
$info = mysqli_real_escape_string($con,file_get_contents($_FILES['file']['tmp_name']));