PHP将图片存入mysql后再显示出来(支持多张)
<?php $form_description = $_POST['form_description']; $form_data_name = $_FILES['form_data']['name']; $form_data_size = $_FILES['form_data']['size']; $form_data_type = $_FILES['form_data']['type']; $form_data = $_FILES['form_data']['tmp_name']; //echo "winson"; // ßB½Óµ½ÙYÁÏŽì $connect = MYSQL_CONNECT( "localhost", "root", "admin") or die("Unable to connect to MySQL server"); mysql_select_db("blogsystem") or die("Unable to select database"); $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); //echo "mysqlPicture=".$data; $result=MYSQL_QUERY( "INSERT INTO ccs_image (description,bin_data,filename,filesize,filetype) VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')"); $id= mysql_insert_id(); print "<p>This file has the following Database ID: <a href='get_data.php?id=$id'><b>$id</b></a>"; MYSQL_CLOSE(); ?>
2. [文件] get_data.php
<?php if(isset($_GET['id'])) { $id = $_GET['id']; $connect = MYSQL_CONNECT("localhost", "root", "admin") or die("Unable to connect to MySQL server"); mysql_select_db("blogsystem") or die("Unable to select database"); $query = "select bin_data,filetype from ccs_image where id=$id"; $result = @MYSQL_QUERY($query); $out=mysql_fetch_array($result); $data=$out["bin_data"]; $type=$out["filetype"]; Header( "Content-type: $type"); echo $data; } if(isset($_GET["pic_id"])) { $pic_id = $_GET['pic_id']; $connect = MYSQL_CONNECT("localhost", "root", "admin") or die("Unable to connect to MySQL server"); mysql_select_db("blogsystem") or die("Unable to select database"); $query = "select * from ccs_image where id=$pic_id"; $result = @MYSQL_QUERY($query); $out=mysql_fetch_array($result); echo $out["id"]; } ?>
3. [文件] new_file.php
<?php $connect = MYSQL_CONNECT( "localhost", "root", "admin") or die("Unable to connect to MySQL server"); mysql_select_db("blogsystem") or die("Unable to select database"); $sql="select * from ccs_image"; $result=mysql_query($sql) or die(mysql_error()); while($out=@mysql_fetch_array($result)) { echo "<img style='style:height:100px;width:100px;' src='get_data.php?id=".$out['id']."' onmouseover='see_big(".$out['id'].")' /><br/>"; } ?> <script src="jquery.js?1.1.6"></script> <script type="text/javascript"> $(document).ready(function(){ }); function see_big(id) { var pic_id=id; $.ajax({ type: "GET", data: "pic_id="+pic_id, url: "get_data.php", dataType:'text', success:function(data) { $("#big_pic img").attr("src","get_data.php?id="+data); } }) } </script> <p id="big_pic" style="height: 500px;width: 600px;position: absolute;margin-left: 200px;margin-top: -550px;"> <img /></p> <center> <form method="post" action="form.php" enctype="multipart/form-data"> File Description: <input type="text" name="form_description" size="40"> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000"> <br> File to upload/store in database: <input type="file" name="form_data" size="40"> <p><input type="submit" name="submit" value="submit"> </form> </center>
以上就是PHP将图片存入mysql后再显示出来(支持多张)的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool