Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_POST['submit'])){
- $file_url = $_POST['file_url'];
- $new_name = $_POST['new_name'];
- // Inisialisasi cURL
- $ch = curl_init($file_url);
- // Menentukan opsi untuk menyimpan hasil download ke variabel
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- // Melakukan request
- $data = curl_exec($ch);
- // Menutup koneksi cURL
- curl_close($ch);
- // Mendapatkan informasi nama file asli jika `<link>$new_name</link>` kosong
- if(empty($new_name)){
- $path_parts = pathinfo($file_url);
- $new_name = $path_parts['basename'];
- }
- // Menyimpan file ke folder uploads dengan nama baru
- if(file_put_contents('uploads/' . $new_name, $data) !== false){
- $file_url = 'http://' . $_SERVER['HTTP_HOST'] . '/uploads/' . $new_name;
- $file_size = filesize('uploads/' . $new_name);
- $file_size_mb = round($file_size/1024/1024, 2); // Mengonversi ukuran file ke MB
- echo "File berhasil diunggah. <br>";
- echo "Nama file: <link>$new_name</link> <br>";
- echo "Ukuran file: $file_size_mb MB <br>";
- echo "Link: <a href='$file_url'>$file_url</a>";
- } else {
- echo "Gagal mengunggah file.";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement