douji1999 2010-07-20 12:58
浏览 70

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

<?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);
  }
?>

I am using the above code to generate the captcha image in codeigniter. When i use this code got error message as

PHP Error was encountered Severity: Warning Message: imagecolorallocate(): supplied argument is not a valid Image resource Filename: plugins/captcha_pi.php Line Number: 236

A PHP Error wasencountered Severity: Warning Message: imagecolorallocate(): supplied argument is not a valid Image resource Filename: plugins/captcha_pi.php Line Number: 237

A PHP Error was encountered Severity: Warning Message: imagecolorallocate(): supplied argument is not a valid Image resource Filename: plugins/captcha_pi.php Line Number: 238

A PHP Error was encountered Severity: Warning Message: imagettftext() expects parameter 1 to be resource, boolean given Filename: plugins/captcha_pi.php Line Number: 251

A PHP Error was encountered Severity: Warning Message: imagejpeg(): supplied argument is not a valid Image resource Filename: plugins/captcha_pi.php Line Number: 259

A PHP Error was encountered Severity: Warning Message: imagedestroy(): supplied argument is not a valid Image resource Filename: plugins/captcha_pi.php Line Number: 263

Please give me the solution for this if anybody knows

  • 写回答

1条回答 默认 最新

  • douyue6520 2010-07-20 13:01
    关注

    This line is your problem:

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

    I recommend changing that path and trying again...

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

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能