Downloads
Download pages with countdown and captcha, tokens, the package's limits, X-Sendfile / X-Accel / LiteSpeed hand-off, speed caps, zip bundles and the download tracker.
A file's public address is /<short>/<name>, for example /Euz/trailer.mp4. That page is the download page: a preview, the file's details, the countdown or the instant button, the free-versus-premium comparison, and the advertisements that pay for free downloads. The real transfer is /dl/<token>/<name>, and that is where every limit is enforced. This chapter covers both.
The download page
What a visitor sees depends on the file and on their package:
- Preview - pictures, video and audio show on the page (video and audio in the AIO Player with its advertisements); documents and code open when the File Previewer plugin is on. The setting
download_page_preview(0in the settings table) switches the preview off. - Password - a protected file asks for it first (
file-passwordtemplate); a private file is only reached by its link when Private files open by their link is on. - Minimum account type - a file the owner limited to a package tells lower types This file needs a higher account type to download.
- Countdown - the package's Countdown Before Download seconds, or the countdown of the download page assigned to that package (below). Packages with Instant Downloads skip it. Owners never wait.
- Captcha after the countdown for visitors and/or free users (Site Settings → Captcha: Downloads: visitors, Downloads: free users).
- Compare - a table of Download Type, Download Speed, Maximum Waiting Time, Site Advertising, How Long To Keep Files, Maximum File Upload Size and Estimated Download Time for the free package against the first paid package on
/upgrade, with the Account benefits list from Site Settings → Premium Pricing. - Links - direct, HTML, BBCode and Markdown codes for the file.
- Advertisements at Download page, top, bottom and right side, and in the player.
The stats page is /<short>/<name>~s, the report form /report_file.
Download pages per account type
Admin → Configuration → Download Pages assigns a template to a package (Set Download Page To User Type): compare_timed (the two choices with a countdown), compare_all (without the countdown), simple_timed (just the countdown) or redirect (the delayed-redirect page with its own two ad positions). Each row has a Countdown (seconds), a Page order (several pages for one type are walked through in order) and optional File Types so, say, only videos get a page. A type with no row downloads directly. The install seeds compare_timed for Free User (10 s) and Temp User (15 s). Copy a template from themes/boxpuff/templates/download/ into your own theme to change its look.
Tokens
Pressing the button makes a token: 64 hex characters, kept in bp_download_tokens so every file server with the same database can honour it. It lives Download link lifetime (minutes) (default 180) and, with Lock download links to the IP enabled, only works from the address that asked (switch it off if a proxy breaks the document viewer). The player's streams use six-hour tokens without the IP lock. Expired tokens are purged by the cron.
Limits
/dl/ checks the package again before a single byte goes out (Account packages):
| Field | Refusal |
|---|---|
| Wait Between Downloads | Please wait N seconds between downloads. |
| Concurrent Downloads | You already have the maximum number of downloads running. |
| Max Daily Download Quantity / Max Daily Download Filesize | Reached in 24 hours. |
| Max Download Size | This file is larger than your account may download. |
| a per-user bandwidth allowance (Edit User → Advanced) | Your download allowance is used up. |
The owner of a file is never limited. The wait and concurrent limits need Site Settings → File Downloads → Track current downloads on; the same tracker feeds Admin → Files → Active Downloads. Also under File Downloads: Require an account to download, Block all downloads (maintenance), Block countries from downloading (ISO codes), and Block download managers for free users with the Blocked user agents list (IDM, FDM, JDownloader, wget, curl, aria2, yt-dlp and friends) - paid accounts get download manager support.
How the bytes are sent
download_send() chooses the cheapest path:
- A link straight to the storage. A bucket (S3 and friends) or a web-served FTP/SFTP folder gives a signed link and the browser is redirected there; the site's bandwidth is untouched. Direct bucket links only for unlimited speed keeps speed-capped packages streaming through the site instead.
- A Direct file server hands out its own files: the download address is built on the file server's domain, which shares the database and honours the token.
- The web server sends a local file when the server's Improved Downloads is set:
X-Sendfile(Apache with mod_xsendfile),X-Accel-Redirect(Nginx, with an internal location for/files/) orX-LiteSpeed-Location. PHP sets the headers and is free at once. Used when the package has no speed cap. Left at its default (Disabled), Improved Downloads still picksX-Sendfileby itself when PHP runs as an Apache module andmod_xsendfileis loaded, so a server that has the module is fast without a setting; Nginx and LiteSpeed still have to be named, because they need their own server changes first. - PHP streams it with
Rangesupport (resumable, seekable video),HEADanswered, and the package's Download Speed cap in bytes per second enforced by sleeping between blocks. Without a cap the file is read and sent in 1 MB pieces (fewer system calls, a full pipe), with output buffering, Apache compression and proxy buffering switched off for the stream and the session released first, so a long download never holds up the member's other pages. A speed-capped package uses smaller blocks sized to its cap.
Inline views (?inline=1, used by previews and the player) send the file's own content type; HTML and SVG are served as plain text so nothing uploaded can run in the visitor's browser.
If downloads feel slow
BoxPuff cannot send bytes faster than the server's connection to the visitor. Download speed is the pipe your host gives the machine, shared with every other site on it, and the visitor's own line. To tell the script from the pipe, compare: put a big static file (a 100 MB zip) in the site's folder outside files/, download it by its direct address, and then download a file of the same size from BoxPuff. If the static file is just as slow, the limit is the server or the network, not BoxPuff; move to a faster host, a bucket with a CDN (File servers) or Cloudflare. If only BoxPuff is slow, look at the package's Download Speed cap, whether Improved Downloads is in effect, and the server's load.
Zip bundles
Several files, or a whole folder, go out as one zip streamed while it is made (includes/zipstream.php) - nothing is written to disk first, and the folder structure is kept. The package needs Enable Download Bundle (Zip); Zip download max size (bytes) (default 4 GB) caps the selection. Temporary zips in uploads/zips/ older than Zip purge hours are swept by the cron.
The download tracker and statistics
Each download writes a row in bp_downloads with IP, country, browser, referrer and bytes; Stats count unique only counts one address once a day. Rows older than Keep per-download rows (days) (default 400) are squashed into daily totals by the cron job Statistics roll-up. The file's own counters and last_access feed the inactivity rules (Days To Keep Inactive Files). Members see their numbers in the file manager's Stats; the admin on the file's Stats and Downloads tabs and on the dashboard (Top Download Countries).
Per-package speed with Nginx
The fields Upload Url Slug and Download Url Slug on a package add a folder name to the upload and download addresses (/free/dl/...), so an Nginx location /free/ block can apply limit_rate to one package without PHP doing the throttling.
Tips
- On a VPS, set Improved Downloads on the local server first; it is the single biggest speed win.
- Give free users a countdown and a speed cap, and premium Instant Downloads, no advertisements and download manager support - the comparison table then sells the upgrade by itself.
- Watch Active Downloads on a busy day; if the list is long and the server slow, move the files to a bucket or add a Direct server (File servers).