首页 文章

提供的参数不是php codeigniter中的有效Image资源

提问于
浏览
1
<?php
  if (!defined('BASEPATH'))
      exit('No direct script access allowed');
  function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '')
  {
      $defaults = array('word' => '', 'word_length' => 6, 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_path' => '', 'expiration' => 7200);
      foreach ($defaults as $key => $val) {
          if (!is_array($data)) {
              if (!isset($$key) or $$key == '') {
                  $$key = $val;
              }
          } else {
              $$key = (!isset($data[$key])) ? $val : $data[$key];
          }
      }
      if ($img_path == '' or $img_url == '') {
          return false;
      }
      if (!@is_dir($img_path)) {
          return false;
      }
      if (!is_really_writable($img_path)) {
          return false;
      }
      if (!extension_loaded('gd')) {
          return false;
      }





      list($usec, $sec) = explode(" ", microtime());
      $now = ((float)$usec + (float)$sec);
      $current_dir = @opendir($img_path);
      while ($filename = @readdir($current_dir)) {
          if ($filename != "." and $filename != ".." and $filename != "index.html") {
              $name = str_replace(".jpg", "", $filename);
              if (($name + $expiration) < $now) {
                  @unlink($img_path . $filename);
              }
          }
      }
      @closedir($current_dir);



      $pool = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
      $str = '';
      for ($i = 0; $i < 6; $i++) {
          $str .= substr($pool, mt_rand(0, strlen($pool) - 1), 1);
      }
      $text = $str;



      $im = @imagecreatefromjpeg('".base_url()."\images\captch.jpg');

      $white = imagecolorallocate($im, 255, 255, 255);
      $grey = imagecolorallocate($im, 128, 128, 128);
      $black = imagecolorallocate($im, 0, 0, 0);



      $font = '".base_url()."system\fonts\Alan Den.ttf';



      imagettftext($im, 30, 0, 10, 40, $black, $font, $text);



      $now = date('YmdHis');
      $img_name = $now . '.jpg';

      imagejpeg($im, $img_path . $img_name);
      $img = "<img src=\"" . base_url() . "$img_url$img_name\"   style=\"border:0;\" alt=\" \" />";
      imagedestroy($im);
      return array('word' => $text, 'time' => $now, 'image' => $img);
  }
?>

我使用上面的代码在codeigniter中生成验证码图像 . 当我使用此代码获取错误消息时

遇到PHP错误严重性:警告消息:imagecolorallocate():提供的参数不是有效的图像资源文件名:plugins / captcha_pi.php行号:236 PHP错误wasencountered严重性:警告消息:imagecolorallocate():提供的参数不是有效的图像资源文件名:plugins / captcha_pi.php行号:237遇到PHP错误严重性:警告消息:imagecolorallocate():提供的参数不是有效的图像资源文件名:plugins / captcha_pi.php行号:238 A PHP遇到错误严重性:警告消息:imagettftext()期望参数1为资源,给定布尔值文件名:plugins / captcha_pi.php行号:251遇到PHP错误严重性:警告消息:imagejpeg():提供的参数不是有效的图像资源文件名:plugins / captcha_pi.php行号:259遇到PHP错误严重性:警告消息:imagedestroy():提供的参数不是有效的图像资源文件名:plugins / cap tcha_pi.php行号:263

如果有人知道,请给我解决方案

1 回答

  • 0

    这行是你的问题:

    $im = @imagecreatefromjpeg('".base_url()."\images\captch.jpg');
    

    我建议改变那条路,再试一次......

    $im = @imagecreatefromjpeg("images\\captch.jpg");
    

相关问题