php 8.0 으로 업그레이드후 발생하는 에러입니다

php 8.0 으로 업그레이드후 발생하는 에러입니다

QA

php 8.0 으로 업그레이드후 발생하는 에러입니다

본문


/**
     * 배열을 지정한 파일로 저장 - 폴더에 웹서버의 쓰기 권한이 있어야 함
     */
    public function save_file($outvar, $filename, $info=array(), $int=false) {
        $fp = @fopen($filename, 'w');
        $contents  = "<?php\n";
        $contents .= "if (!defined('_EYOOM_')) exit;\n";
        $contents .= "\$" . $outvar . " = array(\n";
        if ($info != NULL) {
            foreach ($info as $key => $value) {
                if (!is_array($value)) {
                    // 키값으로 정수를 허용하지 않는다면
                    if (!$int) {
                        if (!is_int($key)) {
                            $contents .= "\t\"" . addslashes($key) . "\" => \"" . addslashes($value) . "\",\n";
                        }
                    } else $contents .= "\t\"" . addslashes($key) . "\" => \"" . addslashes($value) . "\",\n";
                } else {
                    $arr = '';
                    foreach ($value as $k => $v) {
                        if (!$int) {
                            if (!is_int($key)) {
                                $arr .= "\"" . addslashes($k) . "\" => \"" . addslashes($v) . "\",";
                            }
                        } else $arr .= "\"" . addslashes($k) . "\" => \"" . addslashes($v) . "\",";
                    }
                    if ($arr) {
                        $arr = substr($arr,0,-1);
                        $contents .= "\t\"" . addslashes($key) . "\" => array(" . $arr . "),\n";
                    }
                }
            }
        }
        $contents .= ");\n";
        @fwrite($fp, $contents);
        @fclose($fp);
        @chmod($filename, 0644);
    }

 

PHP Fatal error:  Uncaught TypeError: fclose(): Argument #1 ($stream) must be of type resource, bool given in /home/www/eyoom/class/qfile.class.php:93
 

php 7.4 에서 8.0 으로 업그레이드를 했는데 위와같은 오류가 나옵니다

 

해당 구문은   @fwrite($fp, $contents);     @fclose($fp);    이 두개 입니다.

어떻게 수정해야 오류가 안날까요?

 

이 질문에 댓글 쓰기 :

답변 1


...
        $fp = @fopen($filename, 'w');
        
        if ($fp === false) {
            return;
        }
        
        $contents  = "<?php\n";
...
답변을 작성하시기 전에 로그인 해주세요.
전체 69
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT