다른 사이트(로컬)의 파일을 클라이언트가 설치할 수 있게 해주는 php 코드 예제 > 코딩 스토리

다른 사이트(로컬)의 파일을 클라이언트가 설치할 수 있게 해주는 php 코드 예제

페이지 정보

작성자 이름으로 검색 (192.♡.0.1) 작성일 23-07-20 23:02 조회 8,020 댓글 1

본문

[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 '파일 다운로드 실패';

}

?>

[/code]
사이트의 접속 또는 다운로드 차단을 회피할 수 있고, 사진 동영상 html, js, css 파일 정도를 다운로드 할 수 있을 것으로 예상됨
좋아요95 이 글을 좋아요하셨습니다
url 복사 카카오톡 공유 라인 공유 페이스북 공유 트위터 공유

카테고리 분류 학습 시스템 (총 0개 학습됨)

예측 카테고리: 문학 (랜덤 - 학습 데이터 없음)

이 분류가 맞나요? 학습시켜주세요!

2kat님의 댓글

no_profile 2kat쪽지보내기 자기소개 아이디로 검색 전체게시물 아이피 (220.♡.000.000) 작성일

좋네요

😶
❤️
😂
😅
😮
😡
🥵
  • RSS
  • _  글쓰기 글쓰기
전체 302건
게시물 검색

접속자집계

오늘
2,157
어제
3,897
최대
42,418
전체
940,385