l

glob함수로 인한 문제

· 2013-04-22 (월) 23:52:42 · 1551 · 1
서버에 따라 glob 함수가 지원되지 않거나 제대로 된 값을 전송하지 못하는 문제가 있습니다. 그 결과로

1. 캡차 이미지가 제대로 구현되지 않거나 혹은 에러를 발생합니다.
2. 최신글 등록이 되지 않거나 목록이 비어있습니다.

그래서 glob함수를 대체하기 위해 php.net 사이트를 참조하여 safe_glob함수를 만들어 보았습니다.

아래의 코드를 lib/common.lib.php 의 if (!defined('_GNUBOARD_')) exit;라고 되어 있는 코드 바로 아래에 붙여 넣기를 하고 glob함수를 safe_glob으로 대체하면 됩니다. glob함수가 사용되고 있는 부분은 다 확인하지 못했지만 최소 다음과 같습니다.

lib/common.lib.php
plugin/gcaptcha/gcaptcha.lib.php
adm/thumbnail_file_delete.php
adm/cache_file_delete.php
** 태진하님이 알려주신대로 두 파일을 추가했습니다. **


[code]
//
// 서버에서 glob이 지원되지 않거나 올바른 값을 주지 못하는 문제로 인해 {{{
//
define('G4_GLOB_SUPPORT', function_exists('glob') && count(glob(G4_PATH.'/*.php')));

function safe_glob($pattern)
{
if (G4_GLOB_SUPPORT) return glob($pattern);

$output = array();

$pattern = str_replace('\\', '/', $pattern); #change backslashes to slashes
$slash = '/';

$lastpos = strrpos($pattern, $slash);
if (!($lastpos === false)) {
$path = substr($pattern, 0, $lastpos);
$pattern = substr($pattern, $lastpos+1);
} else {#no dir info, use current dir
$path = getcwd();
}
$handle = @opendir($path);

if ($handle === false) return false;

while ($dir = readdir($handle)) {
if (safe_glob_pattern_match($pattern, $dir)) $output[] = $path.'/'.$dir;
}
closedir($handle);
//if (is_array($output)) return $output;
return $output;
//return false; #return value should be always an array
}

function safe_glob_pattern_match($pattern, $string)
{
#basically prepare a regular expression
$out = null;
$chunks = explode(';', $pattern);
foreach ($chunks as $pattern) {
$escape = array('$','^','.','{','}', '(',')','[',']','|');
while (strpos($pattern,'**') !== false) $pattern = str_replace('**', '*', $pattern);
foreach ($escape as $probe) $pattern = str_replace($probe, "\\$probe", $pattern);
$pattern = str_replace('?*', '*', str_replace('*?', '*', str_replace('*', ".*", str_replace('?', '.{1,1}', $pattern))));
$out[] = $pattern;
}
if(count($out) == 1) return eregi("^$out[0]$", $string);
else {
foreach($out as $tester) {
if(eregi("^$tester$", $string)) return true;
}
}
return false;
}

//
// }}}
//
[/code]
|

댓글 1개

정말 대단하십니다.

이 문제로 고심했었는데...

해결되어서 무척 기쁘네요..

고생하셨습니다.

참고적으로...

관리자 모드에서 썸네일 및 캐쉬파일 일괄삭제시..

adm/thumbnail_file_delete.php
adm/cache_file_delete.php

두 파일도

glob 함수를 safe_glob 바꾸어주면 잘 작동됩니다.
댓글을 작성하시려면 로그인이 필요합니다.

버그신고

4,191건

  문의게시판을 이용해 주세요 :) https://sir.kr/co_qa  

+
분류 제목 글쓴이 날짜
13-04-30
13-04-30
13-04-30
13-04-29
13-04-29
13-04-29
13-04-27
13-04-27
13-04-27
13-04-26
13-04-26
13-04-25
13-04-24
13-04-24
13-04-23
13-04-23
13-04-23
13-04-22
13-04-21
13-04-19