开发者

show img src from mysql_query()

开发者 https://www.devze.com 2023-03-12 11:06 出处:网络
I wanna show image with <img src=\"here a query\" > Im doing my insert like that. mysql_query(\"INSERT INTO imagenez (ID, imagenes) VALUES (NULL, \'{$_FILES[\'userfile\'][\'name\']}\')\");

I wanna show image with <img src="here a query" >

Im doing my insert like that.

mysql_query("INSERT INTO imagenez (ID, imagenes) VALUES (NULL, '{$_FILES['userfile']['name']}')");

And now i wanna take my picture for im开发者_开发技巧g. its possible? if not, please a alternative way.


You might want to consider what will happen if a user uploads a picture with a filename like s'); DROP TABLE imagenez; --.

Always sanitize your inputs.


Create a new PHP page that displays the image.

<?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;
?>

Now in your HTML output, use the new page with the image id to display.

<img src="image.php?ID=12" />
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号