我正在使用php創建圖像,我幾乎編碼了它,但是我在一個非常重要的點上發現了一個問題,我希望在該圖像中選擇我選擇的字體系列,但只有當我選擇字體系列時,纔會使用默認字體。此邏輯運行不正常。當我沒有選擇任何字體家族的默認字體運行,並顯示我的輸入,但是當我選擇任何字體,然後它也運行和現有的圖像覆蓋,但它沒有顯示我的屏幕上的輸入。在php中創建圖像
請告訴我什麼是問題。這裏是我的PHP代碼文件:
<?php
include_once('includes/includes.inc.php');
if(isset($_GET['txt'])){
$txt = $_GET['txt'];
$_SESSION['txt'] = $txt;
}
if(!isset($_SESSION['rand'])){
$rand = mt_rand(100,1000);
$_SESSION['rand'] = $rand;
}
$im = @imagecreate(288, 288) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 230, 248, 248);
$text_color = imagecolorallocate($im, 85, 85, 85);
if(isset($_GET['Smile'])){
$query = mysql_query("SELECT * FROm tbl_fonts WHERE font_name = '".$_GET['Smile']."'");
$get = mysql_fetch_array($query);
$desfon = 'images/fonts/'.$get['font_name'].'.ttf';
//echo $desfon;
imagettftext($im, 55, 0, 155, 55, $text_color, $desfon, $_SESSION['txt']);
}
else{
imagestring($im, 55, 155, 55, $_SESSION['txt'], $text_color);
}
header("Content-Type: image/png");
$filename1 = $_SESSION['txt'].$_SESSION['rand'].'.png';
imagepng($im,$filename);
echo '<img src="'.$filename.'" alt="" />';
?>
如果只有您的圖像沒有顯示是因爲瀏覽器緩存。嘗試使用圖像源添加時間戳,因此它總是使用最新的圖像,如
首先,您必須在使用$ _SESSION之前調用session_start() –
這將允許攻擊者在當前用戶有權訪問的任何地方寫入文件。在使用它作爲文件名之前,您可能需要清理$ _GET ['txt']的內容。 – MatsLindh