❶ PHP代碼輸出圖片的問題
應該是這樣寫
<?php
echo "<center>"鬧激; /困碼/居中開始標簽
echo "<img src='./logo.jpg' />"; //當前目錄下的這一張圖片
echo "</center>"; //居汪彎哪中結束標簽
?>
❷ php怎麼輸出圖片
首先爛緩設置頭部
header("Content-type: image/png");
然飢搏模後創銀伏建圖片等操作
最後輸出:
imagepng($im,"1.png");
❸ PHP怎麼輸出一張圖片
<?php
塵局$t=imagecreatetruecolor(100,100);
$red=imagecolorallocate($t,255,0,0);
imagefill($t,0,0,$red);
header('Content-type:image/png');
imagepng($t);
配兄畝培森imagedestroy($t);
?>
❹ PHP實現上傳圖片到資料庫並顯示輸出的方法
本文實例講述了PHP實現上傳圖片到資料庫並顯示輸出的方法。分享給大家供大家參考,具體如下:
1.
創建數據表
CREATE
TABLE
ccs_image
(
id
int(4)
unsigned
NOT
NULL
auto_increment,
description
varchar(250)
default
NULL,
bin_data
longblob,
filename
varchar(50)
default
NULL,
filesize
varchar(50)
default
NULL,
filetype
varchar(50)
default
NULL,
PRIMARY
KEY
(id)
)engine=myisam
DEFAULT
charset=utf8
2.
用於上傳圖片到伺服器的頁面
upimage.html
<!doctype
html>
<html
lang="en">
<head>
<meta
charset="UTF-8">
<meta
name="viewport"
content="width=device-width,
user-scalable=no,
initial-scale=1.0,
maximum-scale=1.0,
minimum-scale=1.0">
<meta
http-equiv="X-UA-Compatible"
content="ie=edge">
<style
type="text/css">
*{margin:
1%}
</style>
<title>Document</title>
</head>
<body>
<form
method="post"
action="upimage.php"
enctype="multipart/form-data">
描述:
<input
type="text"
name="form_description"
size="40">
<input
type="hidden"
name="MAX_FILE_SIZE"
value="1000000">
<br>
上傳文件到資料庫:
<input
type="file"
name="form_data"
size="40"><br>
<input
type="submit"
name="submit"
value="submit">
</form>
</body>
</html>
3.
處理圖片上傳的php
upimage.php
<?php
if
(isset($_POST['submit']))
{
$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'];
$dsn
=
'mysql:dbname=test;host=localhost';
$pdo
=
new
PDO($dsn,
'root',
'root');
$data
=
addslashes(fread(fopen($form_data,
"r"),
filesize($form_data)));
//echo
"mysqlPicture=".$data;
$result
=
$pdo->query("INSERT
INTO
ccs_image
(description,bin_data,filename,filesize,filetype)
VALUES
('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
if
($result)
{
echo
"圖片已存儲到資料庫";
}
else
{
echo
"請求失敗,請重試";
注:圖片是以二進制blob形式存進資料庫的,像這樣
4.
顯示圖片的php
getimage.php
<?php
$id
=2;//
$_GET['id'];
為簡潔,直接將id寫上了,正常應該是通過用戶填入的id獲取的
$dsn='mysql:dbname=test;host=localhost';
$pdo=new
PDO($dsn,'root','root');
$query
=
"select
bin_data,filetype
from
ccs_image
where
id=2";
$result
=
$pdo->query($query);
$result=$result->fetchAll(2);
//
var_mp($result);
$data
=
$result[0]['bin_data'];
$type
=
$result[0]['filetype'];
Header(
"Content-type:
$type");
echo
$data;
到瀏覽器查看已經上傳的圖片,看是否可以顯示
是沒有問題的,證明圖片已經以二進制的形式存儲到資料庫了
更多關於PHP相關內容感興趣的讀者可查看本站專題:《php+mysql資料庫操作入門教程》、《php+mysqli資料庫程序設計技巧總結》、《php面向對象程序設計入門教程》、《PHP數組(Array)操作技巧大全》、《php字元串(string)用法總結》及《php常見資料庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
您可能感興趣的文章:php實現上傳圖片保存到資料庫的方法php上傳圖片存入資料庫示例分享php上傳圖片到指定位置路徑保存到資料庫的具體實現php中如何將圖片儲存在資料庫里php下將圖片以二進制存入mysql資料庫中並顯示的實現代碼php
從資料庫提取二進制圖片的處理代碼php將圖片保存入mysql資料庫失敗的解決方法php將圖片文件轉換成二進制輸出的方法php圖片的二進制轉換實現方法
❺ php輸出圖片有問題,求高手謝謝!!!!
<?php
$image = '1.jpeg';
$img = GetImageSize($image); //獲枯租鬧得數組的一些信息!Array ( [0] => 240 [1] => 320 [2] => 2 [3] => width="240" height="320" [bits] => 8 [channels] => 3 [mime] => image/jpeg )
//var_mp($img);
switch ($img[2]) {
case 1 :
$im = imagecreatefromgif($image);break; //將圖片型友轉化為PHP可識別的編碼過程
case 2 :
$im = imagecreatefromjpeg($image);break;
case 3 :
$im = imagecreatefrompng($image);break; //$im 是個真彩圖片
break;
}
$te = imagecolorallocate($im, 255, 255, 255);
$str = iconv("gbk", "utf-8", "新年垮了"); //需要將GBK轉化為UTF-8才能將中文輸出
imagettftext($im, 12, 9, 20, 20, $te, 'STCAIYUN.TTF', $str);
header("Content-type: image/jpeg");
//imagejpeg($im);
//iconv()
//imagettftext()
?>
// 確保沒罩有這個字體文件存在 STCAIYUN.TTF
// iconv() 可以
❻ php 讀取圖片並輸出
<?php
header('Content-Type:image/png');
$url="http://hbyw.e21.e.cn/global/gd.php";//圖片鏈接
$ch=curl_init();
//Cookie:PHPSESSID=
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_COOKIE,'PHPSESSID=');//如果不需要cookies就刪除這條語句
curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);
curl_setopt($ch,CURLOPT_TIMEOUT,0);//忽略超時
curl_setopt($ch,CURLOPT_NOBODY,false);
$str=curl_exec($ch);
curl_close($ch);
❼ PHP怎麼輸出圖片啊我的圖片1.jpg和new.php在同一位置為什麼圖片不能顯示
new.php裡面如下的語句輸出好滲碧1.jpg:
<?php
echo
"<img
src='1.jpg'>";
?>
你可以單獨把以上語句存為一個PHP文件試試看,如果成功了,說明沒有其它問題,可能是你的1.jpg的實際喊亂名字中有空格或者引號等特殊符號,或者名字含有中文而PHP文件是UTF編碼,這樣就會造成找不到文件,改為1.JPG試試看。
如果文件名確實是1.JPG,友舉而且是上面的單獨的PHP文件,仍然無法顯示,可以在瀏覽器圖片的紅叉上點滑鼠右鍵查看屬性,看看顯示的網址,檢查是不是指向了你希望的文件夾位置。
❽ php輸出圖片無法顯示,文件頭部有空白
你在或雹第2種方式里,除了 img 輸出外,還有其它輸出。
請參看下面的示例代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?<a href="https://www..com/s?wd=php&tn=44039180_cpr&fenlei=_5y9YIZ0lQzqlpA-" target="_blank" class="-highlight">php</a>
// 創建新的圖像實例
$<a href="https://www..com/s?wd=im&tn=44039180_cpr&fenlei=_5y9YIZ0lQzqlpA-" target="_blank" class="-highlight">im</a> = <a href="https://www..com/s?wd=im&tn=44039180_cpr&fenlei=_5y9YIZ0lQzqlpA-" target="_blank" class="-highlight">im</a>agecreatetruecolor(100, 100);
// 設置背景為白色
imagefilledrectangle($im, 0, 0, 99, 99, 0xFFFFFF);
//在圖像上寫字
imagestring($im, 3, 40, 20, 'GD Library', 0xFFBA00);
//echo "這一行如果加上就不能正常顯示下面的圖像沖純了。";
// 輸出圖像到瀏覽器
header('Content-Type: image/gif');
imagegif($im);
imagedestroy($im);
?>
為什麼第 2 種方式,不能在header前面有內容,究其原因,請參看以下說明:散團咐
header()必須在任何實際輸出之前調用,不管是普通的html標簽,還是文件裡面的空行、空格或者是PHP文件里的空行、空格。
簡單一句話:在header()被調用之前有輸出就會出錯。
❾ php輸出圖片
這是我做的,php+mysql,根據資料庫中的數據動態輸出圖片
$cn=mysql_connect('localhost','root','');
$strsql="select * from zuobiao";
$result=mysql_db_query("caipiao",$strsql,$cn);
while($arr=mysql_fetch_array($result)){
$linex1=$arr[x10];
$linex2=$arr[x9];
$linex3=$arr[x8];
$linex4=$arr[x7];
$linex5=$arr[x6];
$linex6=$arr[x5];
$linex7=$arr[x4];
$linex8=$arr[x3];
$linex9=$arr[x2];
$linex10=$arr[x1];
$liney1=$arr[y10];
$liney2=$arr[y9];
$liney3=$arr[y8];
$liney4=$arr[y7];
$liney5=$arr[y6];
$liney6=$arr[y5];
$liney7=$arr[y4];
$liney8=$arr[y3];
$liney9=$arr[y2];
$liney10=$arr[y1];
}
mysql_close($cn);
header("content-type:image/png"顫仿辯);//設定生成圖片格式
$im=@imagecreate(130,316);//創建一個圖片實例,大小為130*316
$background_color = imagecolorallocate ($im, 211, 255, 242);//背大襲景顏色
$red=imagecolorallocate($im,255,0,0); //設定$red為紅色
$blue=imagecolorallocate($im,0,0,150);//設定$blue為藍色
imageline($im,$linex1,$liney1,$linex2,$liney2,$red);
imageline($im,$linex2,$liney2,$linex3,$liney3,$red);
imageline($im,$linex3,$liney3,$linex4,$liney4,$red);
imageline($im,$linex4,$liney4,$linex5,$liney5,$red);
imageline($im,$linex5,$liney5,$linex6,$liney6,$red);
imageline($im,$linex6,$liney6,$linex7,$liney7,$red);
imageline($im,$linex7,$liney7,$linex8,$liney8,$red);
imageline($im,$linex8,$liney8,$linex9,$liney9,$red);
imageline($im,$linex9,$liney9,$linex10,$liney10,$red);
imageline($im,$linex10,$liney10,$linex11,$liney11,$red);
imageline($im,$linex11,$liney11,$linex12,$liney12,$red);
imageline($im,$linex12,$liney12,$linex13,$liney13,$red);
imageline($im,$linex13,$liney13,$linex14,$liney14,$red);
imageline($im,$linex14,$liney14,$linex15,$liney15,$red);
imagepng($im,'pic/abc.png');//生成png圖茄缺片
imagedestroy($im);//注銷$im
❿ php中怎麼輸出圖片
<divclass="flexslider">
<ulclass="slides">
<?php
if($info->tupian==""){
echo宏拍"暫無圖片"蔽敏羨;
}
else
{
echo"<lidata-thumb='".$info->tupian."'><divclass='thumb-image'><imgsrc='".$info->tupian."'data-imagezoom='true'class='mg-responsive'></div></li>";
}
?>
<拿高/ul>
</div>