显示图像。 [英] displaying images.

查看:82
本文介绍了显示图像。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个允许您显示图像的网站代码。但是,从将图像存储到数据库,一切正常,但它不显示图像。


以下代码是我使用过的代码。

存储图像:


[PHP]< HTML>

< HEAD>< TITLE>将二进制数据存储到SQL数据库< / TITLE>< / HEAD>

< BODY>


<?php


if(isset($ _ REQUEST [''submit''])){


mysql_connect(" localhost" ,root,"");

mysql_select_db(" binary_data");


$ data = addslashes(fread(fopen($ _FILES [''form_data''] [''tmp_name'']," r"),$ _FILES [''form_data''] [''size'']));


$ result = mysql_query(" INSERT INTO binary_data(description,bin_data,filename,filesize,filetype)" ;.

" VALUES(''"。$ form_description。"' , '' " $数据" '', '' " $ _ FILES [ '' form_data ''] [ '' 姓名 '']" '', '' " $ _ FILES [ '' form_data ''] [ '' 尺寸 '']" '', '' " $ _ F。 ILES [''form_data''] [''type'']。"'')");


$ id = mysql_insert_id();

print"< p>此文件包含以下数据库ID:< b> $ id< / b>" ;;


mysql_close();


}否则{

?>

< form method =" post"行动= QUOT; store.php" enctype =" multipart / form-data">

文件说明:< br>

< input type =" text"名称= QUOT; form_description" size =" 40">

< INPUT TYPE =" hidden"名称= QUOT; MAX_FILE_SIZE" value =" 1000000">

< br>要在数据库中上传/存储的文件:< br>

< input type =" file" name =" form_data">

< p>< input type =" submit"命名= [提交" value =" submit">

< / form>


<?php


}


?> [/ PHP]

从数据库中获取图像:


[PHP]<?php


if($ id){


mysql_connect(" localhost"," root","");


mysql_select_db(" binary_data");


$ query =" ;从表中选择bin_data,filetype,其中id =''$ id''" ;;

$ result = mysql_query($ query);


$ data = mysql_result($ result,0," bin_data");

$ type = mysql_result($ result,0," filetype");


header(" Content-type:$ type");

header(" Content-type:image / pjpeg");

echo $ data;



};

?> [/ PHP]

显示图片:


[PHP]< html>

< head>

< title >从数据库中检索的图像< / title>

< / head>


< body>


< img src =" getdata.php?id = 3">


< / body>

< / html> [/ PHP]


如果有人可以提供帮助我会非常感激。


谢谢


ashraf

i used a code from a website that allows you to display images. however everything works fine from storing the image to the database but it does not display the image.

the following code is the one i have used.

Storing the images:

[PHP]<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>

<?php

if (isset($_REQUEST[''submit''])) {

mysql_connect("localhost","root","");
mysql_select_db("binary_data");

$data = addslashes(fread(fopen($_FILES[''form_data''][''tmp_name''], "r"), $_FILES[''form_data''][''size'']));

$result= mysql_query("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
"VALUES (''".$form_description."'',''".$data."'',''".$_FILES[''form_data''][''name'']."'',''".$_FILES[''form_data''][''size'']."'',''".$_FILES[''form_data''][''type'']."'')");

$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";

mysql_close();

} else {
?>
<form method="post" action="store.php" enctype="multipart/form-data">
File Description:<br>
<input type="text" name="form_description" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="form_data">
<p><input type="submit" name="submit" value="submit">
</form>

<?php

}

?>[/PHP]

Getting the image from database :

[PHP]<?php

if($id) {

mysql_connect("localhost","root","");

mysql_select_db("binary_data");

$query = "select bin_data,filetype from table where id=''$id''";
$result = mysql_query($query);

$data = mysql_result($result,0,"bin_data");
$type = mysql_result($result,0,"filetype");

header( "Content-type: $type");
header( "Content-type: image/pjpeg");
echo $data;


};
?>[/PHP]

displaying the image:

[PHP]<html>
<head>
<title>images retrieved from database</title>
</head>

<body>

<img src="getdata.php?id=3">

</body>
</html>[/PHP]

if someone can help i would greatly appreciate it.

thanks

ashraf

推荐答案

_REQUEST [''submit'' ])){$ / $

mysql_connect(" localhost"," root","");

mysql_select_db(" binary_data");

_REQUEST[''submit''])) {

mysql_connect("localhost","root","");
mysql_select_db("binary_data");


data = addslashes(fread(fopen(
data = addslashes(fread(fopen(


_FILES [''form_data''] [''tmp_name ''],r,
_FILES[''form_data''][''tmp_name''], "r"),


这篇关于显示图像。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆