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

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

QA

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

답변 1

본문


/**
     * 배열을 지정한 파일로 저장 - 폴더에 웹서버의 쓰기 권한이 있어야 함
     */
    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

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 129,102
© SIRSOFT
현재 페이지 제일 처음으로