search
Homephp教程PHP源码PHP将图片存入mysql后再显示出来(支持多张)

PHP将图片存入mysql后再显示出来(支持多张)

<?php
$form_description = $_POST[&#39;form_description&#39;];  
$form_data_name = $_FILES[&#39;form_data&#39;][&#39;name&#39;];
$form_data_size = $_FILES[&#39;form_data&#39;][&#39;size&#39;];
$form_data_type = $_FILES[&#39;form_data&#39;][&#39;type&#39;];
$form_data = $_FILES[&#39;form_data&#39;][&#39;tmp_name&#39;];
//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 (&#39;$form_description&#39;,&#39;$data&#39;,&#39;$form_data_name&#39;,&#39;$form_data_size&#39;,&#39;$form_data_type&#39;)");  

$id= mysql_insert_id();  
print "<p>This file has the following Database ID: <a href=&#39;get_data.php?id=$id&#39;><b>$id</b></a>";


MYSQL_CLOSE();
?>

2. [文件] get_data.php 

<?php  
if(isset($_GET[&#39;id&#39;])) {  
$id = $_GET[&#39;id&#39;];
$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[&#39;pic_id&#39;];
    $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=&#39;style:height:100px;width:100px;&#39; 
    	src=&#39;get_data.php?id=".$out[&#39;id&#39;]."&#39; onmouseover=&#39;see_big(".$out[&#39;id&#39;].")&#39; /><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:&#39;text&#39;,
			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)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SecLists

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

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool