Я пытаюсь сгенерировать график с помощью php GD. Я передаю данные из HTML в функцию графика контроллера. Все это работает на моем локальном хосте, но на моем живом сервере графическое изображение не создается. Я использую PHP 5.5 на моем локальном компьютере с Ubuntu 14.04 … Живой сервер использует Php 5.4 на Debian Wheezy … Я проверил на обеих машинах установлена библиотека GD ..
После проверки некоторых я подозреваю, что я делаю что-то неправильно, когда делаю urlencode и urldecode или, на мой взгляд, при создании многомерного массива.
Вот моя функция графика контроллера:
public function graph1()
{
include('phpgraphlib.php');
$graph = new PHPGraphLib(600,300);
$data1 = unserialize(urldecode(stripslashes($_GET['mydata1'])));
$line1 = array_column($data1, 'line1');
$line2 = array_column($data1, 'line2');$graph->addData($line1,$line2);
$graph->setBars(false);
//$graph->setGrid(false);
$graph->setGridColor("238, 238, 238");
$graph->setLine(true);
$graph->setDataPoints(true);
$graph->setDataPointColor('160,160,160');
$graph->setDataValues(true);
$graph->setDataValueColor('0,0,0');
$graph->setGoalLine(.0025);
$graph->setGoalLineColor('red');
$graph->setLineColor("255, 167, 78", "67, 162, 255","blue");
//$graph->setLegend(true);
//$graph->setLegendTitle("Apples", "Pears");
$graph->createGraph();
}
Вот мой взгляд, откуда я передаю свои данные:
<?php
$data1 = array();
foreach ($line1 as $field => $label){
if (count($points) > 0 && isset($points[0]->$field)){
$i = 0;
$total = count($points);
$total = $total > 30 ? 30 : $total;
foreach ($points as $point){
if ($i >= $total){
break;
}
$data1 []['line1'] = $point -> $field;
$i++;
}
}
}
foreach ($line2 as $field => $label){
if (count($points) > 0 && isset($points[0]->$field)){
$i = 0;
$total = count($points);
$total = $total > 30 ? 30 : $total;
foreach ($points as $point){
if ($i >= $total){
break;
}
$data1 []['line2'] = $point -> $field;
$i++;
}
}
}
<img src="<?php echo site_url('/g1/g2/graph1')."?mydata1=".urlencode(serialize($data1)); ?>" />
Этот код не создает изображение на живом сервере. Действительно здорово, если кто-нибудь может подсказать мне, что делать?
Вот значение url для imgsrc с моего локального хоста:
http://localhost/site/index.php/g1/g2/graph1?mydata1=a%3A12%3A%7Bi%3A0%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A2%3A%2292%22%3B%7Di%3A1%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22144%22%3B%7Di%3A2%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22110%22%3B%7Di%3A3%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22100%22%3B%7Di%3A4%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22365%22%3B%7Di%3A5%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22185%22%3B%7Di%3A6%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22176%22%3B%7Di%3A7%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22234%22%3B%7Di%3A8%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22358%22%3B%7Di%3A9%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22201%22%3B%7Di%3A10%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22144%22%3B%7Di%3A11%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22112%22%3B%7D%7D
Вот значение URL img src с сервера Live:
https://mysite.com/index.php/g1/g2/graph1?mydata1=a%3A12%3A%7Bi%3A0%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A2%3A%2292%22%3B%7Di%3A1%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22144%22%3B%7Di%3A2%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22110%22%3B%7Di%3A3%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22100%22%3B%7Di%3A4%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22365%22%3B%7Di%3A5%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22185%22%3B%7Di%3A6%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22176%22%3B%7Di%3A7%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22234%22%3B%7Di%3A8%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22358%22%3B%7Di%3A9%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22201%22%3B%7Di%3A10%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22144%22%3B%7Di%3A11%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22112%22%3B%7D%7D
Также, если я установлю pdf debug tru, то эта ошибка отладки будет показана на живом сервере:
mPDF error: IMAGE Error (https://mysite.com/index.php/g1/g2/graph1?mydata1=a%3A12%3A%7Bi%3A0%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A2%3A%2292%22%3B%7Di%3A1%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22144%22%3B%7Di%3A2%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22110%22%3B%7Di%3A3%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22100%22%3B%7Di%3A4%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22365%22%3B%7Di%3A5%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22185%22%3B%7Di%3A6%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22176%22%3B%7Di%3A7%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22234%22%3B%7Di%3A8%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22358%22%3B%7Di%3A9%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22201%22%3B%7Di%3A10%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22144%22%3B%7Di%3A11%3Ba%3A1%3A%7Bs%3A5%3A%22line1%22%3Bs%3A3%3A%22112%22%3B%7D%7D): Could not find image file
Как вы обнаружили, функция PHP array_column
начал свою жизнь с PHP 5.5.
http://php.net/manual/en/function.array-column.php
(PHP 5> = 5.5.0)
Таким образом, для дружественного кода 5.4 вы можете заменить:
$line1 = array_column($data1, 'line1');
$line2 = array_column($data1, 'line2');
С:
$line1 = array();
$line2 = array();
foreach ( $data1 as $line_array ) {
if ( isset($line_array['line1']) ) { $line1[] = $line_array['line1']; }
if ( isset($line_array['line2']) ) { $line2[] = $line_array['line2']; }
}
Вот демоверсия, которую вы можете использовать здесь: http://writecodeonline.com/php/
<?php
$data1 = array(
array('line1' => 165)
, array('line1' => 180)
, array('line1' => '')
, array('line1' => 140)
, array('line2' => '')
, array('line2' => 50)
, array('line2' => 68)
, array('line2' => 80)
);
$line1 = array();
$line2 = array();
foreach ( $data1 as $line_array ) {
if ( isset($line_array['line1']) ) { $line1[] = $line_array['line1']; }
if ( isset($line_array['line2']) ) { $line2[] = $line_array['line2']; }
}
print_r($line1);
print_r($line2);
?>
print_r
-ing $ line1 и $ line2 дают мне:
Array
(
[0] => 165
[1] => 180
[2] =>
[3] => 140
)
Array
(
[0] =>
[1] => 50
[2] => 68
[3] => 80
)
Других решений пока нет …