A. 用php的file_get_content函數讀取圖片為什麼得到的字元串是亂碼
讀出來是亂碼是正常的,畢竟圖片是二進制文件,直接寫入文件就可以了,你輸出的時候聲明是圖片的頭就沒問題了
B. 求 PHP 圖片驗證碼類 給出詳細調用方法 謝謝!!!
[code.php]
<?php
/**
*驗證碼圖片
*/
session_start();
Header("Content-type:image/gif");
/*
*初始化
*/
$border=0;//是否要邊框1要:0不要
$how=4;//驗證碼位數
$w=$how*15;//圖片寬度
$h=20;//圖片高度
$fontsize=10;//字體大小
$alpha="abcdefghijkmnpqrstuvwxyz";//驗證碼內容1:字母
$number="23456789";//驗證碼內容2:數字
$randcode="";//驗證碼字元串初始化
srand((double)microtime()*1000000);//初始化隨機數種子
$im=ImageCreate($w,$h);//創建驗證圖片
/*
*繪制基本框架
*/
$bgcolor=ImageColorAllocate($im,255,255,255);//設置背景顏色
ImageFill($im,0,0,$bgcolor);//填充背景色
if($border)
{
$black=ImageColorAllocate($im,0,0,0);//設置邊框顏色
ImageRectangle($im,0,0,$w-1,$h-1,$black);//繪制邊框
}
/*
*逐位產生隨機字元
*/
for($i=0;$i<$how;$i++)
{
$alpha_or_number=mt_rand(0,1);//字母還是數字
$str=$alpha_or_number?$alpha:$number;
$which=mt_rand(0,strlen($str)-1);//取哪個字元
$code=substr($str,$which,1);//取字元
$j=!$i?4:$j+15;//繪字元位置
$color3=ImageColorAllocate($im,mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));//字元隨即顏色
ImageChar($im,$fontsize,$j,3,$code,$color3);//繪字元
$randcode.=$code;//逐位加入驗證碼字元串
}
/*
*如果需要添加干擾就將注釋去掉
*
*以下for()循環為繪背景干擾線代碼
*/
/*+-------------------------------繪背景干擾線開始--------------------------------------------+*/
for($i=0;$i<5;$i++)//繪背景干擾線
{
$color1=ImageColorAllocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));//干擾線顏色
ImageArc($im,mt_rand(-5,$w),mt_rand(-5,$h),mt_rand(20,300),mt_rand(20,200),55,44,$color1);//干擾線
}
/*+-------------------------------繪背景干擾線結束--------------------------------------+*/
/*
*如果需要添加干擾就將注釋去掉
*
*以下for()循環為繪背景干擾點代碼
*/
/*+--------------------------------繪背景干擾點開始------------------------------------------+*/
/*
for($i=0;$i<$how*40;$i++)//繪背景干擾點
{
$color2=ImageColorAllocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));//干擾點顏色
ImageSetPixel($im,mt_rand(0,$w),mt_rand(0,$h),$color2);//干擾點
}
*/
/*+--------------------------------繪背景干擾點結束------------------------------------------+*/
//把驗證碼字元串寫入session方便提交登錄信息時檢驗驗證碼是否正確例如:$_POST['randcode']=$_SESSION['randcode']
$_SESSION['randcode']=$randcode;
/*繪圖結束*/
Imagegif($im);
ImageDestroy($im);
/*繪圖結束*/
?>
[調用方法]
<SCRIPTLANGUAGE="JavaScript">
<!--
functionreloadcode(){
vard=newDate();
document.getElementById('safecode').src="/code.php?t="+d.toTimeString()
}
//-->
</SCRIPT>
驗證碼:<inputname="chknumber"type="text"maxlength="4"class="chknumber_input"/><imgsrc='code.php'id="safecode"onclick="reloadcode()"title="看不清楚?點擊切換!"></img>
C. PHP能夠實現圖片轉文字的功能嗎如果可以的話能告訴一下思路和需要用到的函數
估計不能
否則的話,驗證碼圖片就是多次一舉失去了意義
D. php如何實現,遠程傳一張照片回來,在資料庫進行比對識別,有相同的就取出相關信息
資料庫,你可能保存有圖片的文件名,大小,格式化,來本地文件路徑,
把傳過來的圖片的這三個特徵在資料庫查找一下,如果存在,就幾乎可以判斷是同一個文件,
如果你要更准確一些,就用file_get_contents()把文件內容讀出來進行對比。
E. php中如何調用資料庫中的圖片並且顯示到頁面
php是採用二進制形式存儲圖片及讀取顯示的,首先通過代碼創建數據表,然後上傳圖片伺服器再通過瀏覽器顯示,具體編程代碼舉例:
1、首先需要創建數據表,具體代碼如下圖所示。
F. php中如何從資料庫中讀取圖片
<?php
//將圖片存進資料庫再讀出,注意存儲圖片的欄位類型必須為blob
$user=』root』;
$password=』root』;
$db=』test』;
$connect=mysql_connect(『localhost』,$user,$password);
mysql_set_charset(『utf8′,$connect);
mysql_select_db($db);
$photo = 「0x」.bin2hex(file_get_contents(「./test.jpg」));
$sql=」INSERT INTO `test`.`test` (`photo`) VALUES ($photo);」;//$photo不需要用引號,切記
mysql_query($sql);
//$result=mysql_query(「SELECT *
//FROM `test`
//LIMIT 0 , 30〃);
//$img=mysql_fetch_array($result);
//echo $img['photo'];
?>