ewholzHello Members,I am setting up a photo website. I have decided to use PHP and MySQL.I can load jpeg files into the table (medium blob, or even longtext)and get the image(s) to display without a problem. I am usingchunk_split(data) and the base64_encode and base64_decode on the files.I do a select from the database, and then echo the image (withheader(Content Type: image/jpeg)and the decoded image displays fine. Yes, I have tried header(ContentType: image/png), withoutsuccess.My problem is png images. Is there something that I need to dodifferent in terms on reading/encodeing/decodeing the png image? I amputting its "binary" data into the db table.But when I do a select on a png image - it never displays in thebrowser.I am not using file/path names as references, but actually putting theimage in the db.Here is a sample of code I use to insert the data into the table, andto select the code from the table.load image(s):<?phpwhile ($file = readdir($dir_handle)){$filetyp = substr($file, -3);if ($filetyp == ''png'' OR $filetyp == ''jpg''){$handle = fopen($path . "/" . $file,''r'');$file_content = fread($handle,filesize($path . "/" . $file));fclose($handle);$encoded = chunk_split(base64_encode($file_content));$sql = "INSERT INTO images SET sixfourdata=''$encoded''";mysql_query($sql);}}?>display images:<?php$result = @mysql_query("SELECT * FROM images WHERE id=" . $img . "");if (!$result){echo("Error performing query: " . mysql_error() . "");exit();}while ( $row = mysql_fetch_array($result) ){$imgid = $row["id"];$encodeddata = $row["sixfourdata"];}?><?php//echo base64_decode($encodeddata);echo $encodeddata;?>This process seems to always work with jpegs.Thanksewholz推荐答案 file = readdir(file = readdir( dir_handle)) {dir_handle)){ filetyp = substr(filetyp = substr( 这篇关于将png图像加载到mysql表/数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-17 20:52
查看更多