개발자의 끄적끄적

[php] allow_url_fopen / wrapper is disabled in the server configuration by allow_url_fopen=0 에러 해결 방법 본문

개발/php

[php] allow_url_fopen / wrapper is disabled in the server configuration by allow_url_fopen=0 에러 해결 방법

효벨 2023. 9. 11. 01:00
728x90
반응형

[php] allow_url_fopen / wrapper is disabled in the server configuration by allow_url_fopen=0 에러 해결 방법

 

 

php 에서

 

파일 다운로드 기능을 구현하다보면

 

서버에 있는 파일이 아닌, url만 가지고 파일을 다운로드 해야 하는 경우가 있습니다.

 

그럴때 아래와 같이

 

file_get_contents 를 이용해서 파일정보를 가져오는데요!

 

$data = file_get_contents($file_url);

 

file_get_contents 가 정상적으로 실행이 되지 않고,

 

아래와 같이 allow_url_fopen 에러가 나는 경우가 있습니다!

 

wrapper is disabled in the server configuration by allow_url_fopen=0

 

allow_url_fopen 설정은 php.ini 에서 설정할 수 있지만,

 

클라우드나 호스팅서버의 구성에 따라 파일을 수정할 수 없는 경우도 있습니다!

 

그럴때는 아래와 같이

 

ini_set("allow_url_fopen", 'On'); 을

 

file_get_contents 위에 선언해주시고,

 

다시 실행해보면 정상적으로 다운로드가 되실겁니다!

 

ini_set("allow_url_fopen", 'On');
$data = file_get_contents($file_url);

 

참고들 하세요!

반응형
Comments