Code Download Một Trang Web trong PHP
Để tải một trang web (bao gồm download một file từ URL) trong PHP chúng ta có một số cách khác nhau tuy nhiên cách đơn giản và thuận tiện nhất đó là sử dụng đồng thời 2 hàm fopen()
và file_put_contents()
.
Lưu ý: Để sử dụng hàm fopen()
thì bạn cần cho phép PHP có quyền tải nội dung từ một URL bằng cách thiết lập allow_fopen_url On
. Một số web server theo dạng share hosting tắt chức năng này do đó bạn có thể gặp phải lỗi khi sử dụng hàm fopen()
.
Ở trong đoạn code ví dụ dưới đây, chúng ta sẽ tải về 1 tập tin từ địa chỉ http://example.net/test_file.zip
rồi sau đó lưu trên máy với tên download.zip
:
<?php
file_put_contents("download.zip", fopen("http://example.net/test_file.zip", "r"));
?>
Chúng ta cũng có thể quy định một đường dẫn tuyệt đối cho tập tin download.zip
:
<?php
file_put_contents("/tmp/download.zip", fopen("http://example.net/test_file.zip", "r"));
?>
Khi sử dụng cách trên với PHP phiên bản 5.1.0 trở lên thì dữ liệu sẽ được đọc theo từng phần trong hàm fopen()
và đồng thời dữ liệu tải về này cũng sẽ được lưu trên máy theo từng phần với hàm file_put_contents()
, Điều này sẽ đảm bảo hệ thống không bị lỗi tràn bộ nhớ khi tập tin tải về có kích thước lớn.
Một cách khác đó là sử dụng file_put_contents()
kết hợp với file_get_contents()
như sau:
<?php
file_put_contents("download.zip", file_get_contents("http://example.net/test_file.zip"));
?>
Tuy nhiên với cách trên khi tập tin tải về có kích thước lớn thì hệ thống có nhiều khả năng sẽ bị tràn bộ nhớ vì hàm file_get_contents()
sẽ lưu trừ tạm thời toàn bộ dữ liệu được tải về vào bộ nhớ RAM.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta property="og:url" content="https://www.konami.com/wepes/mobile/c/information/efootball2022/en">
<meta property="og:type" content="website">
<meta property="og:title" content="PES mobile 2021 Official Website | eFootball PES 2021">
<meta property="og:description" content='Experience the award winning gameplay and match excitement from console on mobile!'>
<meta property="og:site_name"
content="PES 2021 PRO EVOLUTION SOCCER Official Website|KONAMI">
<meta property="og:image"
content="https://www.konami.com/wepes/mobile/img/efootball2022/efootball2022_main_pc.jpg"/>
<title>
PES mobile 2021 Official Website | eFootball PES 2021
</title>
<link rel="stylesheet" href="/wepes/mobile/s/src/jquery.mCustomScrollbar.css">
<link rel="stylesheet" href="/wepes/mobile/s/css/style-update_efootball2022.css?v2">
<link rel="apple-touch-icon" href="/wepes/mobile/s/img/apple-touch-icon.png">
<link rel="shortcut icon" href="/wepes/mobile/s/img/favicon.ico" type="image/vnd.microsoft.icon"/>
<link rel="icon" href="/wepes/mobile/s/img/favicon.ico" type="image/x-icon">
<script>
(function (d) {
var config = {
kitId: 'xps0dod',
scriptTimeout: 3000,
async: true,
},
h = d.documentElement, t = setTimeout(function () {
h.className = h.className.replace(/\bwf-loading\b/g, '') + ' wf-inactive';
}, config.scriptTimeout), tk = d.createElement('script'), f = false,
s = d.getElementsByTagName('script')[0], a;
h.className += ' wf-loading';
tk.src = 'https://use.typekit.net/' + config.kitId + '.js';
tk.async = true;
tk.onload = tk.onreadystatechange = function () {
a = this.readyState;
if (f || a && a != 'complete' && a != 'loaded') return;
f = true;
clearTimeout(t);
try {
Typekit.load(config);
} catch (e) {
}
};
s.parentNode.insertBefore(tk, s);
})(document);
</script>
<script src="/wepes/mobile/s/js/jquery-3.1.1.min.js"></script>
<!-- Google Tag Manager --><script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-PCP56SG');</script> <!-- End Google Tag Manager --><script src="/games/s/common/js/analytics.js"></script></head>
<body>
<header class="page_header" id="top">
<div class="content">
<a class="konami-logo" href="/games/"><img src="/ci/logo/konami_logo_normal.png" alt="KONAMI"></a>
<div class="language-list">
<select id="select-language"><option value="/wepes/mobile/c/information/efootball2022/en/"selected>English</option><option value="/wepes/mobile/c/information/efootball2022/en-us/">English US</option><option value="/wepes/mobile/c/information/efootball2022/fr/">Français</option><option value="/wepes/mobile/c/information/efootball2022/de/">Deutsch</option><option value="/wepes/mobile/c/information/efootball2022/it/">Italiano</option><option value="/wepes/mobile/c/information/efootball2022/es/">Español</option><option value="/wepes/mobile/c/information/efootball2022/pt-br/">Português do Brasil</option><option value="/wepes/mobile/c/information/efootball2022/ru/">Русский язык</option><option value="/wepes/mobile/c/information/efootball2022/tr/">Türkçe</option><option value="/wepes/mobile/c/information/efootball2022/id/">Indonesian</option><option value="/wepes/mobile/c/information/efootball2022/ja/">日本語</option><option value="/wepes/mobile/c/information/efootball2022/ko/">한국어</option><option value="/wepes/mobile/c/information/efootball2022/zh-tw/">繁體中文</option><option value="/wepes/mobile/c/information/efootball2022/zh-cn/">简体中文</option></select>
</div>
</div>
</header>
<div class="announce-link">
<a href="./announce"><p>Postponement of the Update to "eFootball™ 2022 (iOS/Android)"</p></a>
</div>
<div class="kv">
</div>
<div class="topcs_title">
<h2>eFootball PES 2021 will be updated to eFootball™ 2022!</h2>
<p class="main_text">
eFootball™ 2022 will be available as an update to eFootball PES 2021 for mobile and will usher in a new generation of football gaming, with enhancements to everything from the game engine to the way you experience the game. (Updated 05/11/2021) </p>
</div>
<div class="wrapper">
<div class="update2022">
<article class="information">
<div class="pagetop" id="pagetop"><a href="#top" class="scroll-to" id="move-page-top"></a></div>
To this end, we decided to create a new football engine, with a revamped animation system and improved game commands. <br>
We went back to the drawing board for the entire gameplay experience, adding new levels of excitement everywhere, including how player signings and development work. <br>
Get ready for a revolutionary football gaming experience with eFootball™! </p>
<div class="official_website_link"><a
href="/efootball/en">See official website for more details</a>
</div>
</div>
</div>
</div>
<div class="topics_other" id="update">
<h2>Update Overview</h2>
<dl>
<dt> How to Update from eFootball PES 2021 to eFootball™ 2022</dt>
<dd>We want to make sure our fans who have enjoyed eFootball PES 2021 for mobile over the last years will continue enjoying the perfect football experience with eFootball™ 2022. With that in mind, we will be releasing it as an app update rather than a new installation, as with previous years. </dd>
<dt id="update_schedule"> Update Schedule</dt>
<dd>
<span class="add_data">
The update is currently planned for spring 2022. (Updated 05/11/2021)<br>
</span>
Keep an eye on this website for more information. </dd>
</div>
<section class="bottom_area">
<div class="page_link">
<ul>
<li>
<a href="/wepes/mobile/en/">HOME</a>
</li>
</ul>
</div>
</div>
<div class="copy">
<ul>
<li>Apple and the Apple logo are trademarks of Apple Inc., registered in the U.S. and other
countries. App Store is a service mark of Apple Inc.
</li>
<li>Google Play and the Google Play logo are trademarks of Google Inc.</li>
<li>Unreal® Engine, Copyright 1998 - 2019, Epic Games, Inc. All rights reserved.</li>
</ul>
<ul class="platform-copyright">
<li>"
<svg class="icon-ps" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 84.5 65.2">
<g>
<path d="M32.5,0.1V61l13.8,4.4V14.3c0-2.4,1.1-4,2.8-3.4c2.2,0.6,2.7,2.8,2.7,5.2v20.4c8.6,4.1,15.3,0,15.3-10.9
c0-11.2-4-16.2-15.6-20.2C46.9,3.8,38.4,1.2,32.5,0.1z"/>
<path d="M48.9,56.4L71,48.5c2.5-0.9,2.9-2.2,0.9-2.8c-2-0.7-5.7-0.5-8.2,0.4l-14.8,5.2v-8.3l0.8-0.3c0,0,4.3-1.5,10.3-2.2
c6-0.7,13.3,0.1,19.1,2.3c6.5,2.1,7.2,5.1,5.6,7.2C83,52.1,79,53.6,79,53.6L48.9,64.4V56.4z"/>
<path d="M7.2,55.6c-6.7-1.9-7.8-5.8-4.7-8c2.8-2.1,7.6-3.6,7.6-3.6l19.7-7v8L15.6,50c-2.5,0.9-2.9,2.2-0.9,2.8
c2,0.7,5.7,0.5,8.3-0.4l6.8-2.5v7.2c-0.4,0.1-0.9,0.2-1.4,0.2C21.7,58.4,14.4,58,7.2,55.6"/>
<path d="M77.6,62c0-0.7,0.3-1.4,0.8-1.9c0.5-0.5,1.2-0.8,1.9-0.8c0.7,0,1.4,0.3,1.9,0.8c0.5,0.5,0.8,1.2,0.8,1.9
c0,1.5-1.2,2.7-2.7,2.7c-0.7,0-1.4-0.3-1.9-0.8C77.9,63.4,77.6,62.7,77.6,62z M80.3,65.2c0.9,0,1.7-0.3,2.3-0.9
c0.6-0.6,0.9-1.4,0.9-2.3c0-0.9-0.3-1.7-0.9-2.3c-0.6-0.6-1.4-1-2.3-1c-1.8,0-3.2,1.5-3.2,3.2c0,0.9,0.3,1.7,0.9,2.3
C78.6,64.9,79.4,65.2,80.3,65.2"/>
<path d="M81.2,61.2c0,0.2-0.1,0.3-0.2,0.4c-0.1,0.1-0.3,0.1-0.5,0.1h-1v-1h1.1c0.1,0,0.3,0,0.3,0.1C81.1,60.8,81.2,61,81.2,61.2
z M81.9,63.5c0,0-0.1-0.1-0.1-0.2c0-0.1,0-0.1,0-0.3l0-0.5c0-0.2,0-0.4-0.1-0.5c-0.1-0.1-0.1-0.1-0.2-0.2
c0.1-0.1,0.2-0.2,0.3-0.3c0.1-0.1,0.1-0.3,0.1-0.5c0-0.4-0.2-0.7-0.5-0.9c-0.2-0.1-0.4-0.1-0.7-0.1H79h-0.1v0.1v3.4v0.1H79h0.5
h0.1v-0.1v-1.4h1c0.2,0,0.3,0,0.4,0.1c0.1,0.1,0.2,0.2,0.2,0.4l0,0.6c0,0.1,0,0.2,0,0.3c0,0.1,0,0.1,0,0.1l0,0h0h0.6h0.1v-0.1
L81.9,63.5L81.9,63.5L81.9,63.5"/>
</g>
</svg>
","PlayStation" and "
<svg class="logo-ps5" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 283.14 56.69">
<g>
<path class="st0" d="M273.47,51.04h-1.9v-0.64h4.52v0.64h-1.85v5.65h-0.77V51.04z"/>
<path class="st0" d="M280.04,56h0.02l1.77-5.6h1.31v6.3h-0.74v-5.72h-0.02l-1.87,5.72h-0.96l-1.81-5.72h-0.02v5.72H277v-6.3h1.3
L280.04,56z"/>
</g>
<g>
<path class="st0" d="M115.11,56.69c8.42,0,15.24-6.82,15.24-15.24V15.24c0-5.07,4.11-9.18,9.18-9.18h29.57
c0.22,0,0.4-0.18,0.4-0.4V0.4c0-0.22-0.18-0.4-0.4-0.4h-35.62c-8.42,0-15.24,6.82-15.24,15.24v26.22c0,5.07-4.11,9.19-9.19,9.19
H79.9c-0.22,0-0.4,0.18-0.4,0.4v5.24c0,0.22,0.18,0.4,0.4,0.4H115.11z"/>
<path class="st0" d="M181.75,21.3l0-20.89c0-0.22,0.18-0.4,0.4-0.4l80.51,0c0.22,0,0.4,0.18,0.4,0.4v5.24
c0,0.22-0.18,0.4-0.4,0.4h-68.4c-0.22,0-0.4,0.18-0.4,0.4v13.61c0,2.41,1.95,4.36,4.36,4.36l50.93,0
c8.91,0,16.13,7.22,16.13,16.13s-7.22,16.13-16.13,16.13h-66.99c-0.22,0-0.4-0.18-0.4-0.4v-5.25c0-0.22,0.18-0.4,0.4-0.4h60.93
c5.56,0,10.06-4.49,10.08-10.04c0.02-5.56-4.59-10.12-10.16-10.12h-52.07C185.86,30.48,181.75,26.37,181.75,21.3z"/>
<path class="st0" d="M62.17,24.42c5.07,0,9.18-4.11,9.18-9.18c0-5.07-4.11-9.18-9.18-9.18H0.4C0.18,6.05,0,5.87,0,5.65V0.4
C0,0.18,0.18,0,0.4,0l67.82,0c8.42,0,15.24,6.82,15.24,15.24c0,8.42-6.82,15.24-15.24,15.24H21.3c-5.07,0-9.18,4.11-9.18,9.18
v16.62c0,0.22-0.18,0.4-0.4,0.4H0.4c-0.22,0-0.4-0.18-0.4-0.4c0-4.53,0-16.63,0-16.63c0-8.42,6.82-15.24,15.24-15.24H62.17z"/>
</g>
</svg>
","
<svg class="logo-ps4" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 197.9 40.3">
<g>
<path d="M125.5,0L99.2,0c-7.6,0-11.4,4.7-11.4,10.8v18.6c0,3.8-1.8,6.5-5.6,6.5H57.6c-0.2,0-0.3,0.1-0.3,0.3v3.7
c0,0.2,0.1,0.3,0.3,0.3h27.6c7.6,0,11.4-4.7,11.4-10.8V10.8c0-3.8,1.8-6.5,5.6-6.5h23.4c0.2,0,0.3-0.1,0.3-0.3V0.3
C125.8,0.1,125.7,0,125.5,0"/>
<path d="M47.8,0L0.3,0C0.1,0,0,0.1,0,0.3V4c0,0.2,0.1,0.3,0.3,0.3H45c3.8,0,5.6,2.7,5.6,6.5c0,3.8-1.8,6.5-5.6,6.5H9.6
C4.1,17.3,0,21.9,0,28.1l0,11.9c0,0.2,0.1,0.3,0.3,0.3h8.1c0.2,0,0.3-0.1,0.3-0.3V28.1c0-3.8,2.2-6.4,5.3-6.4h33.9
c7.6,0,11.4-4.7,11.4-10.8S55.5,0,47.8,0"/>
<path d="M187.9,31.6l-8.4,0h0.3c-0.2,0-0.3-0.1-0.3-0.3V4.3c0-4.2-2.9-5.5-6.9-3L124.2,31c-1.9,1.2-2.5,2.5-2.1,3.5
c0.4,0.8,1.4,1.4,3.5,1.4l45,0c0.1,0,0.2,0.1,0.3,0.2v3.8c0,0.2,0.1,0.3,0.3,0.3h8.1c0.2,0,0.3-0.1,0.3-0.3v-3.7
c0-0.2,0.1-0.3,0.3-0.3h8.1c0.2,0,0.3-0.1,0.3-0.3v-3.7C188.2,31.8,188.1,31.6,187.9,31.6 M170.9,31.3c0,0.2-0.1,0.3-0.3,0.3
h-37.7c-0.3,0-0.5-0.1-0.5-0.2c0-0.2,0.1-0.3,0.3-0.5l37.6-23.1c0.3-0.2,0.7-0.1,0.7,0.4V31.3z"/>
</g>
<g>
<path d="M192,37.1c0-0.7,0.3-1.4,0.8-1.9c0.5-0.5,1.2-0.8,1.9-0.8c0.7,0,1.4,0.3,1.9,0.8c0.5,0.5,0.8,1.2,0.8,1.9
c0,1.5-1.2,2.7-2.7,2.7c-0.7,0-1.4-0.3-1.9-0.8C192.3,38.4,192,37.8,192,37.1z M194.7,40.3c0.9,0,1.7-0.3,2.3-0.9
c0.6-0.6,0.9-1.4,0.9-2.3c0-0.9-0.3-1.7-0.9-2.3c-0.6-0.6-1.4-1-2.3-1c-1.8,0-3.2,1.5-3.2,3.2c0,0.9,0.3,1.7,0.9,2.3
C193,39.9,193.8,40.3,194.7,40.3"/>
<path d="M195.6,36.2c0,0.2-0.1,0.3-0.2,0.4c-0.1,0.1-0.3,0.1-0.5,0.1h-1v-1h1.1c0.1,0,0.3,0,0.3,0.1
C195.5,35.9,195.6,36,195.6,36.2z M196.3,38.6c0,0-0.1-0.1-0.1-0.2c0-0.1,0-0.1,0-0.3l0-0.5c0-0.2,0-0.4-0.1-0.5
c-0.1-0.1-0.1-0.1-0.2-0.2c0.1-0.1,0.2-0.2,0.3-0.3c0.1-0.1,0.1-0.3,0.1-0.5c0-0.4-0.2-0.7-0.5-0.9c-0.2-0.1-0.4-0.1-0.7-0.1
h-1.6h-0.1v0.1v3.4v0.1h0.1h0.5h0.1v-0.1v-1.4h1c0.2,0,0.3,0,0.4,0.1c0.1,0.1,0.2,0.2,0.2,0.4l0,0.6c0,0.1,0,0.2,0,0.3
c0,0.1,0,0.1,0,0.1l0,0h0h0.6h0.1v-0.1L196.3,38.6L196.3,38.6L196.3,38.6"/>
</g>
</svg>
" are registered trademarks of
Sony Interactive Entertainment Inc.
</li>
<li>Xbox, Xbox One, and the Xbox logos are trademarks of the Microsoft group of companies and are
used under license from Microsoft.</li>
<li>©2021 Valve Corporation. Steam and the Steam logo are trademarks and/or registered trademarks of Valve Corporation in the U.S. and/or other countries.</li>
</ul>
</div>
<footer>
<div class="contents-copyright">©Konami Digital Entertainment</div>
<div class="footer_link">
<ul>
<li><a href="https://legal.konami.com/games/privacy/" target="_blank">Privacy Policy</a></li>
<li><a href="https://www.konami.com/siteinfo/en/">Terms of Use</a></li>
</ul>
</div>
<div class="site-copyright">
<p>©2022 Konami Digital Entertainment</p>
</div>
</footer>
</section>
<script src="/wepes/mobile/s/js/jquery-3.1.1.min.js"></script>
<script src="/wepes/mobile/s/src/remodal.js"></script>
<script src="/wepes/mobile/s/src/jquery.mCustomScrollbar.js"></script>
<script>
(function () {
'use strict';
</script>
</body>
</html>