FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Images retrives
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Images retrives [message #175968 is a reply to message #175966] Fri, 11 November 2011 13:02 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
sritullimilli(at)gmail(dot)com wrote:
> i didn't get the images from mysql database through php script
> i am get this error
>
> <img src='���JFIF
> ...
> plz suggest me
>
> thx&regs

First you need a script like this:
send_picture.php

<?php
open_database(); // some routine to open your picture database..
$id=$_GET['id'];
$query="select picture, picture_filename, picture_size from product
where id='".$id."'";
//echo $query;
$result=mysql_query($query);
if(($result>0) && (($rows=mysql_numrows($result)) == 1)) //got some data
{
$name=mysql_result($result,0,'picture_filename');
$content=mysql_result($result,0,'picture');
$size=mysql_result($result,0,'picture_size');
}
else die();
if ($name="") die();
$mtype=get_mime($name); // if you KNOW what type the picture is, you
dont need this
header("Content-Type: ".$mtype);
header("Content-Disposition: inline; filename=\"".$name."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".strlen($content));
print $content;

// looks up mime type in /etc/mime.types and returns the type, or a
default if unmatched
// makes no attempt to interrogate the file content as such.
// THIS NEEDS MORE WORK!!! it doesn't get all types..espcially DWG/DXF!!
// Mind you we don't want to inmvoke plug-ins for these..
function get_mime($filename)
{
$default="application/force-download";
// first extract the extension
$array=explode(".",$filename); // split the name into the bits
separated by periods
$count=count($array);
if ($count<2) // if there IS NO extension..
return $default; // and let the user sort it out.
$ext=$array[$count-1]; // it will be the last element in the array..
$fp=fopen("/etc/mime.types", "r");
if(!$fp) return ($default); // no /etc/mime.types file
while (!feof($fp))
{ $buffer = fgets($fp, 128);
if (ctype_space($buffer{0}) || $buffer{0}=='#' || $buffer{0}=='\n')
continue; // skip empty lines. or lines starting with spaces
or hashes sscanf($buffer, "%s %s %s %s %s %s
\n",$mime_type,$extension, $extension1, $extension2, $extension3,
$extension4);
if ($ext==$extension || $ext==$extension1 || $ext==$extension2 ||
$ext==$extension3 || $ext==$extension4 )
{
fclose ($fp);
return($mime_type);
}
}
fclose($fp);
return $default;
}
?>

Then in your main php script

printf("<IMG src=\"send_picture.php?id=%d\" >",$id);

where id is the picture id in the database.
..
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: displaying random images with an appropriate caption
Next Topic: Why fsockopen() generates a Warning on timeout?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 17:09:23 GMT 2024

Total time taken to generate the page: 0.05567 seconds