shows a form * - Or direct: https://yourdomain/tera/download.php?url= * * Files are saved into the ./downloads/ folder next to this script and are then * publicly reachable at https://yourdomain/tera/downloads/. * * Requires playterabox.php (for terabox_resolve()) and the PHP cURL extension. */ set_time_limit(0); // big files can take a while @ini_set('max_execution_time', '0'); @ini_set('memory_limit', '256M'); // streaming keeps memory low anyway require __DIR__ . '/playterabox.php'; define('SAVE_DIR', __DIR__ . '/downloads'); // ---- helpers ----------------------------------------------------------- function human_size($bytes) { $bytes = (float) $bytes; $u = ['B', 'KB', 'MB', 'GB', 'TB']; $i = 0; while ($bytes >= 1024 && $i < count($u) - 1) { $bytes /= 1024; $i++; } return round($bytes, 2) . ' ' . $u[$i]; } function sanitize_filename($name) { $name = basename((string) $name); // strip any path parts $name = preg_replace('/[^\w.\- ]+/u', '_', $name); $name = trim($name); return $name !== '' ? $name : ('file_' . substr(md5(uniqid('', true)), 0, 8)); } function unique_path($dir, $filename) { $path = $dir . '/' . $filename; if (!file_exists($path)) return $path; $ext = pathinfo($filename, PATHINFO_EXTENSION); $base = pathinfo($filename, PATHINFO_FILENAME); $i = 1; do { $cand = $dir . '/' . $base . '_' . $i . ($ext ? '.' . $ext : ''); $i++; } while (file_exists($cand)); return $cand; } /** Stream a remote URL straight to disk (memory-safe for large files). */ function download_to_file($url, $destPath) { $fp = @fopen($destPath, 'w'); if (!$fp) return [false, 'Cannot open destination for writing (check folder permissions)']; $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url, CURLOPT_FILE => $fp, // write body directly to file handle CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT => 0, // no cap (host may still enforce one) CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_USERAGENT => 'Mozilla/5.0', CURLOPT_FAILONERROR => true, // treat HTTP >=400 as error ]); $ok = curl_exec($ch); $err = curl_error($ch); $status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); fclose($fp); if (!$ok) { @unlink($destPath); return [false, $err !== '' ? $err : "HTTP $status"]; } return [true, filesize($destPath)]; } // ---- public URL base (auto-detected, works on any domain/subfolder) ---- $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; $dirPath = rtrim(str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'] ?? '')), '/'); $publicBase = "$scheme://$host$dirPath/downloads/"; // ---- main -------------------------------------------------------------- $url = trim($_GET['url'] ?? $_POST['url'] ?? ''); $error = ''; $results = []; if ($url !== '') { if (!is_dir(SAVE_DIR) && !@mkdir(SAVE_DIR, 0755, true)) { $error = 'Could not create downloads/ folder. Create it manually and chmod it 755.'; } else { $r = terabox_resolve($url); if (!$r['ok']) { $error = $r['error']; } else { foreach ($r['files'] as $f) { if (empty($f['download_link'])) { $results[] = ['name' => $f['name'], 'ok' => false, 'error' => 'No download link']; continue; } $dest = unique_path(SAVE_DIR, sanitize_filename($f['name'])); list($ok, $info) = download_to_file($f['download_link'], $dest); $results[] = [ 'name' => $f['name'], 'ok' => $ok, 'saved_as' => basename($dest), 'size' => $ok ? human_size($info) : null, 'error' => $ok ? null : $info, 'public_url' => $ok ? $publicBase . rawurlencode(basename($dest)) : null, ]; } } } } // ---- output ------------------------------------------------------------ header('Content-Type: text/html; charset=utf-8'); ?> TeraBox → cPanel Downloader

TeraBox → cPanel Downloader

❌

✅ Saved as ()
🔗 ❌

Files are stored in downloads/ next to this script. Big files depend on your host's execution-time and disk limits.