【发布时间】:2023-04-04 20:37:02
【问题描述】:
我的根文件夹中名为 tester.php 的文件中有一段代码,并在 CI 视图文件中提供了一个副本。根文件夹中的 tester.php 文件可以正常工作,但视图(或模型、控制器,无论在实际 CI 中的哪个位置)中的代码都不起作用。
使用 CI 2.2.0
这是为什么?
根 tester.php 上的结果:
CI 的结果:
完整代码:
$imageurl = "http://www.example.net/images/images/ABImage_clock_4.jpg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $imageurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$im = imagecreatefromstring ($data);
$bg = imagecolorallocate($im, rand(1,255), rand(1,255), rand(1,255));
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// output text.
$font = 'arial.ttf';
for ($i = 0; $i < 70; $i++) {
imagesetthickness($im, rand(1, 3));
$bg = imagecolorallocate($im, rand(1,255), rand(1,255), rand(1,255));
imagearc(
$im,rand(1, 300), // x-coordinate of the center.
rand(1, 300), // y-coordinate of the center.
rand(1, 300), // The arc width.
rand(1, 300), // The arc height.
rand(1, 300), // The arc start angle, in degrees.
rand(1, 300), // The arc end angle, in degrees.
$bg // A color identifier.
);
}
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
更新
没有错误,并且imageurl确实有效,所以它不是图片链接。
问题: 从根文件夹调用 tester.php 时,它完美运行:
更新 2:
控制器:
class antibot_interface_controller extends CI_Controller {
function getImage() {
$this->load->view('tester');
}
}
查看:
<?
$imageurl = "http://www.textbasedmafiagame.com/images/images/ABImage_clock_4.jpg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $imageurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$im = imagecreatefromstring ($data);
$bg = imagecolorallocate($im, rand(1,255), rand(1,255), rand(1,255));
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// set background colour.
// output text.
$font = 'arial.ttf';
// imagettftext($im, 35, 0, 10, 55, $color, $font, 'ABCD');
for ($i = 0; $i < 70; $i++) {
imagesetthickness($im, rand(1, 3));
$bg = imagecolorallocate($im, rand(1,255), rand(1,255), rand(1,255));
imagearc(
$im,rand(1, 300), // x-coordinate of the center.
rand(1, 300), // y-coordinate of the center.
rand(1, 300), // The arc width.
rand(1, 300), // The arc height.
rand(1, 300), // The arc start angle, in degrees.
rand(1, 300), // The arc end angle, in degrees.
$bg // A color identifier.
);
}
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
路线:
$route['antibot/antibot_image'] = "antibot/antibot_interface_controller/getImage";
EDIT3:
我试图删除文件以检查它是否不起作用。但据我所知是:
$autoload['model'] = array('cartheft/garage_model');
当该模型存在时,图像不会显示。 当我删除该模型时,它会正常工作。
garage_model 文件:
<?
class Garage_model extends CI_model {
}
【问题讨论】:
-
在 CI 中显示你的代码。
-
您的错误日志中有什么内容吗?
-
@NiranjanNRaju 相同的代码。
-
@user2959229 没有错误:/
-
如果 PHP 吐出任何错误消息,这将导致您在浏览器中看到“损坏的图像”图标 - 但您不会看到它们,因为浏览器无法将它们显示为“as”一个图像。在浏览器的网络面板中查看服务器为图像 URL 返回的数据 - 您应该能够在那里看到任何潜在的错误消息。
标签: php codeigniter