脚本宝典收集整理的这篇文章主要介绍了在PHP中显示来自PostgreSQL数据库的图像,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
上传:
echo "<div>". "<table border=\"1\" cellpadding=\"3\">". "<form action=\"test2.PHP\" method=\"post\" enctyPE=\"multipart/form-data\">". "<tr>". "<td>". "<input type=\"file\" name=\"file\" id=\"file\">". "<input class=\"button\" type=\"submIT\" name=\"submit\" value=\"Submit\">". "<tr>". "</tr>". "</form>". "</table>". "</div>";
显示:
if(isset($_FILES['file'])) //file uploaded { $file_raw = file_get_contents($_FILES['file']['tmp_name']); $file = pg_escape_bytea($file_raw); //Here is Code to insert into Database but just to test,I try it directly: header('Content-type: image/png'); echo pg_unescape_bytea($file); }
<?PHP // Connect to the database $dbconn = pg_connect( 'dbname=foo' ); // Read in a binary file $data = file_get_contents( 'image1.jpg' ); // Escape the binary data to avoid PRoblems with encoding $escaped = bin2hex( $data ); // Insert it into the database pg_query( "INSERT INTO gallery (name,data) VALUES ('Pine trees',decode('{$escaped}','hex'))" ); // Get the bytea data $res = pg_query("SELECT encode(data,'base64') AS data From gallery WHERE name='Pine trees'"); $raw = pg_fetch_result($res,'data'); // Convert to binary and send to the browser header('Content-type: image/jpeg'); echo base64_decode($raw); ?>
以上是脚本宝典为你收集整理的在PHP中显示来自PostgreSQL数据库的图像全部内容,希望文章能够帮你解决在PHP中显示来自PostgreSQL数据库的图像所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。