PHP + CodeIgniter:ImageCreateFromJPEG没有加载图片

时间:2012-09-04 23:17:55

标签: php image codeigniter

您好我是PHP和CodeIgniter的新手,我有以下问题

我有一个控制器,我想在其中调用另一个.php上定义的PHP功能。

这是功能:

function createNote($note_text){
     header('Content-type: image/jpeg');
     $note = "./application/controllers/notes/note.jpg";
     $rImg = ImageCreateFromJPEG($note);
     imagejpeg($rImg);

    //After this I want to use the "imagettftext" function to insert the $note_text in
    //the image   
}

这是为了加载该图像并显示它(我猜)但它没有,而是显示以下内容:

enter image description here 我知道图像的路径是正确的,因为如果我更改它,ImageCreateFromJPEF会返回一个错误,说明找不到图像......

有什么想法吗?

提前致谢!

2 个答案:

答案 0 :(得分:1)

故障排除提示:

  1. 您应该检查输出,以确保您在输出之前或之后没有添加任何字符。
  2. 在imageJPEG()之后添加“exit”以防止进一步执行(它将在某处查找视图)。
  3. 执行var_dump($ rImg)并查看(作为普通文件注释掉标题行)以检查图像对象是否正确加载。正如Umair在评论中所说,使用应用程序根的绝对路径或基础来确保正确加载文件。

答案 1 :(得分:0)

在VictorKilo回答后,我搜索了如何设置.htaccess文件。

这个问题给了我很多帮助:How do I write a .htaccess file to make CodeIgniters URL routing work?

之前,我的.htaccess有“全部拒绝”,现在看起来像这样:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|scripts|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

希望这有助于其他人。 感谢您的时间和回答Umair Iqbal,VictorKilo和Robbie。

相关问题