Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.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/8/mysql/70.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_query()显示img src_Php_Mysql - Fatal编程技术网

Php 从mysql_query()显示img src

Php 从mysql_query()显示img src,php,mysql,Php,Mysql,我想用 我这样做我的插入 mysql_query("INSERT INTO imagenez (ID, imagenes) VALUES (NULL, '{$_FILES['userfile']['name']}')"); 现在我想为img拍照。 有可能吗?如果没有,请使用另一种方法。创建一个新的显示图像的PHP页面 <?php //image.php // connect to your DB // get the image from the database $image_id

我想用

我这样做我的插入

mysql_query("INSERT INTO imagenez (ID, imagenes) VALUES (NULL, '{$_FILES['userfile']['name']}')");
现在我想为img拍照。
有可能吗?如果没有,请使用另一种方法。

创建一个新的显示图像的PHP页面

<?php
//image.php

// connect to your DB

// get the image from the database
$image_id = mysql_real_escape_string($_GET['ID']);
$sql = "SELECT imagenes FROM imagenez WHERE ID ='$image_id'";
$result = mysql_query($sql);
$image = mysql_result($result, 0);

// set the content header
//you may need to change this if you have different types of images
header('Content-Type: image/jpeg');
echo $image;
?>

<代码> 您可能想考虑如果用户上传一个像“代码> s”这样的文件名会发生什么情况;下拉表imagenez--


始终清理您的输入。

您到底想做什么?你想把图像存储在哪里?试着更清楚一点你想做什么。我想用html显示图像。使用查询。但是最好将图像作为文件存储在单独的目录中,而不是数据库中。然后,当您需要使用它们时,只需直接引用图像文件即可。您的数据库表将容纳(ID、文件名)。是的,我按照您说的做了。但是我有一个问题,header('Content-Type:image/jpeg')不起作用。我用text/html及其工作来证明。我的问题是什么?如果在标题上出现错误('Content-Type:image/jpeg');最可能的原因是您已经在脚本中开始输出。一旦开始输出,PHP就无法设置HTTP头。在什么都不会发生之前,确保没有任何空白。mysql_query()发送一个唯一的查询(不支持多个查询),当然,它必须防止sql注入;但我也有问题。
<img src="image.php?ID=12" />