自动删除验证码图像CI

时间:2011-12-27 06:57:48

标签: codeigniter captcha

我正在使用CodeIgniter的验证码助手为注册用户生成验证码图像。我有这样的价值:

$vals = array(
        'word' => $rand_word,
        'img_path' => 'resources/captcha/',
        'img_url' => 'http://localhost/fitinline/resources/captcha/',
        'font_path' => './path/to/fonts/texb.ttf',
        'img_width' => 150,
        'img_height' => 40,
        'expiration' => 7200
    );

当我使用create_captcha($vals)函数生成验证码时,验证码图像会自动保存到'img_path'。我设置的到期索引默认为2小时(7200)。但是经过两个多小时后,我检查了'img_path'中的图像,图像仍保存在上面。是否有任何丢失的配置,以启用自动删除那些验证码图像或什么,。?
感谢

2 个答案:

答案 0 :(得分:1)

基于CI文档:

$vals = array(
    'word'   => 'Random word',
    'img_path'   => './captcha/',
    'img_url'    => 'http://example.com/captcha/',
    'font_path'  => './path/to/fonts/texb.ttf',
    'img_width'  => '150',
    'img_height' => 30,
    'expiration' => 7200
    );

“过期”(以秒为单位)表示图像在删除之前将保留在验证码文件夹中的时间。默认值为两小时。

答案 1 :(得分:0)

/*Add script to delete all captcha file*/

$files = glob('./captcha/*'); // get all file names
foreach($files as $file)
{ 
  // iterate files
  if(is_file($file))
    unlink($file); // delete file
}