复制php文件到到另一个目录后不显示是为什么?

徐卡丘 2017-12-26 10:55:02
代码功能是获取数据库的数据然后处理绘制条形图,(没有调用其他文件的东西),在原始文件夹下的文件执行结果:
将整个文件复制粘贴到另一个目录后条形图不显示,只有;通过测试发现数据库的操作能实现,好像只是不能画图;
在header()之前一行加入ob_clean();之后只有条形图显示,图片上的文字不显示,
...全文
201 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
徐卡丘 2017-12-26
  • 打赏
  • 举报
回复
引用 5 楼 qq_34139573 的回复:
[quote=引用 3 楼 tu1425407707 的回复:] [quote=引用 2 楼 qq_34139573 的回复:] 文件目录发生改变,下面$font 对应的字体路径也得改 //字体,字体的大小,标签的位置 $font = 'Arial.ttf';
$font = 'Arial.ttf'; 这里是要加上文件的地址吗? putenv('GDFONTPATH=C:\Windows\Fonts'); 那这句话是什么意思? [/quote] 这个我没怎么用过,只是第一反应应该是这里问题,百度出这个答案 https://zhidao.baidu.com/question/470356603.html[/quote] 恩恩,谢啦
qq_34139573 2017-12-26
  • 打赏
  • 举报
回复
引用 3 楼 tu1425407707 的回复:
[quote=引用 2 楼 qq_34139573 的回复:] 文件目录发生改变,下面$font 对应的字体路径也得改 //字体,字体的大小,标签的位置 $font = 'Arial.ttf';
$font = 'Arial.ttf'; 这里是要加上文件的地址吗? putenv('GDFONTPATH=C:\Windows\Fonts'); 那这句话是什么意思? [/quote] 这个我没怎么用过,只是第一反应应该是这里问题,百度出这个答案 https://zhidao.baidu.com/question/470356603.html
徐卡丘 2017-12-26
  • 打赏
  • 举报
回复
引用 2 楼 qq_34139573 的回复:
文件目录发生改变,下面$font 对应的字体路径也得改 //字体,字体的大小,标签的位置 $font = 'Arial.ttf';
现在已经成功运行了,就是不知道putenv('GDFONTPATH=C:\Windows\Fonts');是什么意思,这里难道不是已经指定了目录了吗?
徐卡丘 2017-12-26
  • 打赏
  • 举报
回复
引用 2 楼 qq_34139573 的回复:
文件目录发生改变,下面$font 对应的字体路径也得改 //字体,字体的大小,标签的位置 $font = 'Arial.ttf';
$font = 'Arial.ttf'; 这里是要加上文件的地址吗? putenv('GDFONTPATH=C:\Windows\Fonts'); 那这句话是什么意思?
qq_34139573 2017-12-26
  • 打赏
  • 举报
回复
文件目录发生改变,下面$font 对应的字体路径也得改 //字体,字体的大小,标签的位置 $font = 'Arial.ttf';
徐卡丘 2017-12-26
  • 打赏
  • 举报
回复
源代码: <?php /** * Created by PhpStorm. * User: Administrator * Date: 2017/12/22 * Time: 18:01 */ /************************************************************ * 连接到MySQL数据库,根据用户投票更新新票数,获得新票数,方便之后的计算 * * **********************************************************/ //$vote = $_REQUEST['vote'];//从HTML中的表单获取用户当前投票人物 //连接poll数据库 if (!$db_conn=new mysqli('localhost', 'root', '', 'poll')) { echo 'Could not connect to db<br />'; exit; } //更新数据库信息 //if (!empty($vote)) { // $vote = addslashes($vote);//处理字段格式 // //MySQL语句 // $query = "update poll_results // set num_votes = num_votes + 1 // where candidate = '$vote'"; // // //操作数据库 // if (!($result = @$db_conn->query($query))) { // echo 'Could not connect to db<br />'; // exit; // } //} //从数据库取出信息 $query = 'select * from poll_results'; if (!($result = @$db_conn->query($query))) { echo 'Could not connect to db<br />'; exit; } $num_candidates = $result->num_rows; $total_votes=0; //总投票数 while ($row = $result->fetch_object()) { $total_votes += $row->num_votes; } $result->data_seek(0);//充值结果指针 /*********************************************** * 初始化图表,创建一些用于实际绘制图形的变量 * * *********************************************/ putenv('GDFONTPATH=C:\Windows\Fonts'); $width = 1000; //图片的宽度(像素方面),这将适合640x480 $left_margin = 100; //图表左边的空间 $right_margin = 100; $bar_height = 80; //柱形图的宽度 $bar_spacing = $bar_height/2; //字体,字体的大小,标签的位置 $font = 'Arial.ttf'; $title_size = 16; $main_size = 12; $small_size = 12; $text_indent = 10; //初始化基线 $x = $left_margin + 120; $y = 100; $bar_unit = ($width - ($x + $right_margin)) / 100; //一个单元的宽度(将图标区域分成一百个单元) //背景总高度 $height = $num_candidates * ($bar_height + $bar_spacing) + 100; /********************************************* * 创建基本图像 * * *******************************************/ //创建一个空白的背景 $im = imagecreatetruecolor($width, $height); //分配颜色 $white = imagecolorallocate($im, 255 , 255, 255); $blue = imagecolorallocate($im, 0, 64, 128); $black = imagecolorallocate($im, 0, 0, 0); $pink = imagecolorallocate($im, 255, 78, 243); $text_color = $black; $percent_color = $black; $bg_color = $white; $line_color = $black; $bar_color = $blue; $number_color = $pink; //绘制中间填充了颜色的矩形 imagefilledrectangle($im, 0, 0, $width, $height, $bg_color); //围绕画布边缘的黑色轮廓线 imagerectangle($im, 0, 0, $width-1, $height-1, $line_color); //添加标题 $title = 'Poll Results'; //imagettfbbox()函数返回文本大小的数组 $title_dimensions = imagettfbbox($title_size, 0, $font, $title); $title_length = $title_dimensions[2] - $title_dimensions[0];//右下x-左下x $title_height = abs($title_dimensions[7]-$title_dimensions[1]); $title_above_line = abs($title_dimensions[7]); $title_x = ($width - $title_length) / 2; $title_y = ($y - $title_height) / 2 + $title_above_line; imagettftext($im, $title_size, 0, $title_x, $title_y, $text_color, $font, $title); //绘制基线 imageline($im, $x, $y-10, $x, $height-30, $line_color); /******************************************************* * 在数据库中逐个检索候选人,计算各自投票百分比,绘制条形图 * * *****************************************************/ while($row = $result->fetch_object()) { if ($total_votes > 0) { $percent = intval(($row->num_votes / $total_votes) * 100); } else { $percent = 0; } $percent_dimensions = imagettfbbox($main_size, 0, $font, $percent.'%'); $percent_length = $percent_dimensions[2] - $percent_dimensions[0]; imagettftext($im, $main_size, 0, $width-$percent_length-$text_indent, $y + ($bar_height / 2), $percent_color, $font, $percent.'%'); $bar_length = $x + ($percent * $bar_unit); //实心条形图 imagefilledrectangle($im, $x, $y-2, $bar_length, $y+$bar_height, $bar_color); //绘制人名 imagettftext($im, $main_size, 0, $text_indent, $y + ($bar_height/2), $text_color, $font, "$row->candidate"); //绘制百分百的轮廓 imagerectangle($im, $bar_length+1, $y-2, ($x + (100 * $bar_unit)), $y + $bar_height, $line_color); //(投票数/总数) imagettftext($im, $small_size, 0, $x + (100 * $bar_unit) - 50, $y + ($bar_height/2), $number_color, $font, $row->num_votes.'/'.$total_votes); $y=$y+($bar_height + $bar_spacing); } ob_clean(); Header('Content-type: image/png'); imagepng($im); //$filename = "../img/poll_result.png"; //imagepng($im, $filename); imagedestroy($im); ?>

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧