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 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错