Php Codeigniter-文件必须位于同一文件夹中

Php Codeigniter-文件必须位于同一文件夹中,php,codeigniter,directory-structure,Php,Codeigniter,Directory Structure,我目前正在使用imagecreatefromjpeg()向图像添加文本。 我的所有文件都在一个文件夹中,但我使用CodeIgniter,所以我的文件分布在不同的文件夹中 实现这一点的变通方法是什么 我想把我所有需要的文件都放在我的视图中,但是那不起作用 请参阅错误 遇到一个PHP错误 严重性:警告 消息:imagettftext():无法找到/打开字体 文件名:views/toucon.php 电话号码:30 参见代码 <?php //Report any errors ini_set("

我目前正在使用
imagecreatefromjpeg()
向图像添加文本。 我的所有文件都在一个文件夹中,但我使用CodeIgniter,所以我的文件分布在不同的文件夹中

实现这一点的变通方法是什么

我想把我所有需要的文件都放在我的视图中,但是那不起作用

请参阅错误

遇到一个PHP错误

严重性:警告

消息:imagettftext():无法找到/打开字体

文件名:views/toucon.php

电话号码:30

参见代码

<?php
//Report any errors
ini_set("display_errors", "1");
error_reporting(E_ALL);
//Set the Content Type
      // header('Content-type: image/jpeg');

      // Create Image From Existing File
      $jpg_image = imagecreatefromjpeg('http://localhost:8888/game/rcw/assets/couponWrite.jpg');


      // Allocate A Color For The Text
      $white = imagecolorallocate($jpg_image, 155, 155, 155);

      // Set Path to Font File
      $font_path = 'http://localhost:8888/game/rcw/application/views/Arial.ttf';

      // Set Text to Be Printed On Image
      $text = "IGL" . rand(55555,99999);

      // Print Text On Image
      imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text);

      // Send Image to Browser
      imagejpeg($jpg_image);

      // Clear Memory
      imagedestroy($jpg_image);


 ?>

您所要做的就是使用图像文件的路径访问图像文件,或者相对于处理图像文件的PHP文件的路径,或者更好地说,使用图像文件的绝对路径。例如,假设您的代码位于控制器中的文件
application/controllers/myImageProcessor.php
中,您希望加载存储在
application/input files
中的文件,在其上写入内容,并将修改后的版本存储在
public/images
中。生成的文件路径如下所示:

// input path is '../input-files/'
$inputPath = dirname(__FILE__).'/input-files/';            // this is an absolute path
$inputName = 'original.jpg';

// output path is '../../public/images/'
$outputPath = dirname(dirname(__FILE__)).'/public/images/';
$outputName = 'modified.jpg';

// load image from file
$img = imagecreatefromjpeg($inputPath.$inputName);

// ...
// write on $img here...
// ...

// save it to other file
imagejpeg($img, $outputPath.$outputName, 95);

将所有文件存储在一个目录中不是一个好主意。此外,不要将代码与HTML/JS/CSS混合使用,也不要将源文件与生成的文件或从外部源检索的文件(例如,由用户上传)放在同一目录中。

您正在使用的代码是什么,您遇到的错误是什么?更多信息。很抱歉@Chilion,已添加代码和错误检查字体路径。程序无法在指定目录中找到Arial.ttf。