开发者

proper way to echo image data from php for Jquery consumption

开发者 https://www.devze.com 2023-04-11 01:03 出处:网络
I have a php function which is called by a jquery function.This jquery function will essentially place the picture on the page.I am having a hard time getting this to work right.I am trying to pin dow

I have a php function which is called by a jquery function. This jquery function will essentially place the picture on the page. I am having a hard time getting this to work right. I am trying to pin down where he problem might lie... My current line of thinking is that I am not sending the data back to my jquery function properly. Here is how I am getting the image

 if(mysql_query("insert into Personal_Photos (Email, Pics) values('$email', '$data')"))
 {
     $query="select Pics, MAX(ID) from Personal_Photos where Email='$email'";
     $result=mysql_query($query) or die("Error: ".mysql_error());
     $row=mysql_fetch_array($result);
     echo '<img src="data:image/jpeg;base64'.base64_encode($row['Pics']).开发者_如何学Go'"/>';
 }

The key line is right here...

echo '<img src="data:image/jpeg;base64,'.base64_encode($row['Pics']).'"/>';

I am wondering if I am doing that incorrectly? How do you do it? Is there a better way to do it. If you notice anything else wrong with my code, I would definitely appreciate the criticism.


data:[<MIME-type>][;charset=<encoding>][;base64],<data>

You need a comma after the base64, which your code block doesn't appear to have (though your individual line you posted has it). Which way is it in your real code?


I would separate this query from the container webpage. I'm not sure if there is a better way, but it's certain that my way is much simpler.

page.html:

<img src="img.php" />

img.php:

<?php
$img=getimg();//get the img binary from mysql and don't base64 it.
echo $img;
?>
0

精彩评论

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