Belum Ada File
File yang diunduh dari URL akan muncul di sini
Semua file tersimpan di folder yang sama dengan script ini$file_url, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 5, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_TIMEOUT => 300, CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36', CURLOPT_HEADER => false, CURLOPT_ENCODING => '', CURLOPT_AUTOREFERER => true, ]); $file_content = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curl_error = curl_error($ch); $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); curl_close($ch); if ($file_content === false || !empty($curl_error)) { $error_message = 'cURL Error: ' . $curl_error; } elseif ($http_code !== 200) { $error_message = "HTTP Error: $http_code"; } } else { // Fallback ke file_get_contents $context = stream_context_create([ 'http' => [ 'timeout' => 300, 'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36', 'follow_location' => true, 'max_redirects' => 5, ], 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, ], ]); $file_content = @file_get_contents($file_url, false, $context); if ($file_content === false) { $error_message = 'Gagal mengunduh dengan file_get_contents'; } } // Proses hasil download if ($file_content === false || !empty($error_message)) { $error = "⌠Gagal mengunduh file!\n" . $error_message; } elseif (empty($file_content) || strlen($file_content) === 0) { $error = '⌠File yang diunduh kosong (0 bytes)!'; } else { // Simpan file ke server $save_result = @file_put_contents($file_path, $file_content, LOCK_EX); if ($save_result === false) { $error = '⌠Gagal menyimpan file ke server! Periksa permission direktori.'; } else { // Set permission file @chmod($file_path, 0644); // Format ukuran file $file_size = formatFileSize($save_result); // Tentukan MIME type $mime_type = 'application/octet-stream'; if (isset($content_type) && !empty($content_type)) { $mime_type = $content_type; } elseif (function_exists('mime_content_type')) { $detected_mime = @mime_content_type($file_path); if ($detected_mime) { $mime_type = $detected_mime; } } $success = "✅ File berhasil diunduh ke server!\n\n"; $success .= "📠Nama File: $custom_filename\n"; $success .= "📊 Ukuran: $file_size\n"; $success .= "📋 Tipe: $mime_type\n"; $success .= "📂 Lokasi: " . basename(__FILE__) . " (folder yang sama)\n"; $success .= "🔗 URL File: " . htmlspecialchars($file_url); } } } } } // Format ukuran file function formatFileSize($bytes) { $units = ['B', 'KB', 'MB', 'GB', 'TB']; $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); $bytes /= pow(1024, $pow); return round($bytes, 2) . ' ' . $units[$pow]; } // Fungsi mendapatkan daftar file yang diunduh function getDownloadedFiles($dir) { $files = []; $current_script = basename(__FILE__); if (is_dir($dir) && is_readable($dir)) { $items = scandir($dir); foreach ($items as $item) { // Skip direktori, file sistem, dan script ini sendiri if ($item === '.' || $item === '..' || $item === $current_script || is_dir($dir . $item)) { continue; } $file_path = $dir . $item; if (is_file($file_path) && is_readable($file_path)) { $files[] = [ 'name' => $item, 'size' => formatFileSize(filesize($file_path)), 'date' => date('Y-m-d H:i:s', filemtime($file_path)), 'path' => $item, 'ext' => strtolower(pathinfo($item, PATHINFO_EXTENSION)), ]; } } } // Sort by date (newest first) usort($files, function($a, $b) { return strcmp($b['date'], $a['date']); }); return $files; } // Dapatkan daftar file $downloaded_files = getDownloadedFiles($download_dir); $total_files = count($downloaded_files); $total_size = 0; foreach ($downloaded_files as $file) { $total_size += filesize($download_dir . $file['name']); } ?>
Unduh file dari URL langsung ke server hosting
âš¡ File tersimpan di folder yang samaFile yang diunduh dari URL akan muncul di sini
Semua file tersimpan di folder yang sama dengan script ini