Images stored in database are cut/cropped when displayed on browser -
i trying display images mysql database. of images display correctly, appear cut/cropped @ bottom , cropped section shows whitespace, can't rid off becomes part of image.
css can't solve , recreating images on go imagecreate etc won't restore it. have meta tags set utf-8. have read, might have utf-8 bom or so. use file_get_contents or fopen , fread images , store them in database , output them using header() or base64_encode. it, same result.
this basic output image code browser:
//html form <form action='' method='post' enctype='multipart/form-data'> <input type='file' name='image' size='10'> <input type='submit' name='submit_image' value='upload' /> </form> //table creation $my_photos = "create table if not exists photos ( id bigint not null auto_increment, pic blob not null, primary key (id) ) engine=innodb"; if (mysql_query($my_photos)){ print "success in photo table creation!"; } else { print "no photos table created. debug code!"; } //get image $uploaded_image = $_files['image']; $image_tmp = $uploaded_image['tmp_name']; $image = file_get_contents($image_tmp); //connect , submit image database mysql_connect("server","username","password"); mysql_select_db("database"); mysql_query("insert ignore photos (id, pic) values ('', '".$image."') "); //get image database , output $image_query = mysql_query("select * photos id=1 "); $image = mysql_fetch_array($image_query); header("content-type: image/jpg/jpeg/gif/png/bmp/jpg"); echo $image['pic'];
has had similar problem , how did fix it?
(i use file system images in app, need blob case).
any appreciated.
handling utf-8 data web client hard in php need alot of things.
first need make sure if html page
<meta http-equiv="content-type" content="text/html; charset=utf-8">
is in webpage
change
<form action='' method='post' enctype='multipart/form-data'>
to
add accept-charset=utf-8 isn't correcly shown here see edit of post see html code..
if php generated add
header('content-type: text/html; charset=utf-8');
on top
after connect database run directly after
mysql_set_charset('utf8')
to tell php mysql client use utf-8 , not latin1 connection.
and think need save photo base64_encoded string keep data correct.
some side notes fix
1) don't use mysql_ annymore mysqli_ 2) html code change (') (") in html attributs
Comments
Post a Comment