다른 사이트(로컬)의 파일을 클라이언트가 설치할 수 있게 해주는 php 코드 예제
본문
[code]
function downloadRemoteFile($url, $filename) {
$userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36';
$referer = 'https://www.google.com/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
if (curl_errno($ch)) {
curl_close($ch);
return false;
}
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status_code == 200) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Content-Length: ' . strlen($data));
echo $data;
return true;
} else {
return false;
}
}
// 다운로드할 PHP 파일의 URL
$phpFileUrl = 'http://example.com/path/to/remote_php_file.php';
// 클라이언트가 다운로드할 때 사용되는 파일명
$clientFileName = 'downloaded_file.php';
if (downloadRemoteFile($phpFileUrl, $clientFileName)) {
echo '파일 다운로드 성공: ' . $clientFileName;
} else {
echo '파일 다운로드 실패';
}
?>
function downloadRemoteFile($url, $filename) {<\/p>
$userAgent = 'Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/91.0.4472.124 Safari\/537.36';<\/p>
$referer = 'https:\/\/www.google.com\/';<\/p>
<\/p>
$ch = curl_init();<\/p>
curl_setopt($ch, CURLOPT_URL, $url);<\/p>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<\/p>
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);<\/p>
curl_setopt($ch, CURLOPT_REFERER, $referer);<\/p>
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);<\/p>
$data = curl_exec($ch);<\/p>
<\/p>
if (curl_errno($ch)) {<\/p>
curl_close($ch);<\/p>
return false;<\/p>
}<\/p>
<\/p>
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);<\/p>
curl_close($ch);<\/p>
<\/p>
if ($status_code == 200) {<\/p>
header('Content-Description: File Transfer');<\/p>
header('Content-Type: application\/octet-stream');<\/p>
header('Content-Disposition: attachment; filename=\"' . $filename . '\"');<\/p>
header('Content-Transfer-Encoding: binary');<\/p>
header('Expires: 0');<\/p>
header('Content-Length: ' . strlen($data));<\/p>
<\/p>
echo $data;<\/p>
return true;<\/p>
} else {<\/p>
return false;<\/p>
}<\/p>
}<\/p>
<\/p>
\/\/ \ub2e4\uc6b4\ub85c\ub4dc\ud560 PHP \ud30c\uc77c\uc758 URL<\/p>
$phpFileUrl = 'http:\/\/example.com\/path\/to\/remote_php_file.php';<\/p>
<\/p>
\/\/ \ud074\ub77c\uc774\uc5b8\ud2b8\uac00 \ub2e4\uc6b4\ub85c\ub4dc\ud560 \ub54c \uc0ac\uc6a9\ub418\ub294 \ud30c\uc77c\uba85<\/p>
$clientFileName = 'downloaded_file.php';<\/p>
<\/p>
if (downloadRemoteFile($phpFileUrl, $clientFileName)) {<\/p>
echo '\ud30c\uc77c \ub2e4\uc6b4\ub85c\ub4dc \uc131\uacf5: ' . $clientFileName;<\/p>
} else {<\/p>
echo '\ud30c\uc77c \ub2e4\uc6b4\ub85c\ub4dc \uc2e4\ud328';<\/p>
}<\/p>
?><\/p>
-
비밀번호를 잊으셨나요? 비밀번호 찾기
SNS 간편 로그인하기
소셜계정으로 로그인
접속자집계
- 오늘
- 2,240
- 어제
- 4,635
- 최대
- 42,418
- 전체
- 1,132,769
2kat님의 댓글
좋네요