php8 로 업그레이드후 발생하는 오류 문의합니다 채택완료
7.4에서 8.0 으로 올린후 두가지 에러가 발생하고 있습니다
</p>
<p>/**
* 외부 이미지 로컬에 저장하기
*/
public function save_url_image($url, $local_image) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata = curl_exec($ch);
curl_close ($ch);</p>
<p> if (file_exists($local_image)){
unlink($local_image);
}
$fp = fopen($local_image,'x');
fwrite($fp, $rawdata);
fclose($fp);
}
PHP Fatal error: Uncaught TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool given Stack trace: #0 /home/www/eyoom/class/bbs.class.php(1087): fwrite() #1 /home/www/eyoom/class/bbs.class.php(1049): bbs->save_url_image()
</p>
<p>// 결과값에서 한행 연관배열(이름으로)로 얻는다.
function sql_fetch_array($result)
{
if( ! $result) return array();</p>
<p> if(function_exists('mysqli_fetch_assoc') && G5_MYSQLI_USE)
try {
$row = @mysqli_fetch_assoc($result);
} catch (Exception $e) {
$row = null;
}
else
$row = @mysql_fetch_assoc($result);</p>
<p> return $row;
}
PHP Fatal error: Uncaught TypeError: mysqli_fetch_assoc(): Argument #1 ($result) must be of type mysqli_result, array given in /home/www/lib/common.lib.php:1825 Stack trace: #0 /home/www/lib/common.lib.php(1825): mysqli_fetch_assoc() #1 /home/www/bbs/search.php(211): sql_fetch_array()
위 두가지 오류를 잡는 방법좀 알려주시면 고맙겠습니다
답변 3개
다음을 참고하셔서 수정을 해보시는건 어떨까 합니다.
1번째 오류
</p>
<p>public function save_url_image($url, $local_image) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata = curl_exec($ch);
curl_close ($ch);
if (file_exists($local_image)){
unlink($local_image);
}
$fp = fopen($local_image,'w'); // 'x' 대신 'w' 모드로 변경
fwrite($fp, $rawdata);
fclose($fp);
}
2번째 오류
</p>
<p>// 결과값에서 한행 연관배열(이름으로)로 얻는다.
function sql_fetch_array($result)
{
if( ! $result) return array();
if(function_exists('mysqli_fetch_assoc') && G5_MYSQLI_USE) {
try {
$row = mysqli_fetch_assoc($result); // mysqli_query로 실행된 결과를 받음
} catch (Exception $e) {
$row = null;
}
}
else
$row = mysql_fetch_assoc($result);
return $row;
}
답변에 대한 댓글 2개
댓글을 작성하려면 로그인이 필요합니다.
save_url_image 이 함수를 실행하는곳의 코드도 함께 올려보세요.
2번 질문도 마찬가지 입니다.
함수에 인자로 들어가는 데이터가 잘못된 겁니다.
댓글을 작성하려면 로그인이 필요합니다.
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인