Sometimes you need to upload a large file but before you pick the very first choice you have to step back and ask yourself what am I trying to achieve in the first place.

Note: Please, read the post first and then watch the video explanation after.

I think the guy from Getting Things Done mentioned that if we think on paper we'd be more effective.

Does the file need to be stored only for a brief period of time?

Who is going to use it?

For many cases you can use a cloud storage such as Dropbox to store the file. You just need to add the file on your computer or upload it via their web interface and share the link.

After the file is downloaded you can delete it.

 

Of course there could be good reasons where you'd definitely and positively need the file to be stored on your own server.

Maybe you want to host a video on your site even though YouTube, Vimeo, Amazon S3 are great options.

One option is to use FTP program to upload the file.

 

One of the services we offer is WordPress migration. We found some effective ways to transfer large files from one server to another.

One of the approaches we've used is to add the large file to a Dropbox folder. This could be the client sharing the file from their account.
The next step is to copy the shared download link.

You have probably noticed that Dropbox adds dl=0 to the each link which is nice because you can just replace the 0 (zero) with 1 and that way the link will become a direct download link.

<?php

// Replace this link with the download link to the large file
// then access this file e.g. http://example.com/dl.php
$url = "http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/current/images/netboot/mini.iso";

// The code is fine but use it at your own risk!
// If you (ab)use it too much your hosting company will contact you because it
// stresses the network and server's hard drives.
// Blog post link: https://orbisius.com/4246

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$dir = __DIR__;

if (!function_exists('shell_exec')) {
	die("Error: The hosting company doesn't allow external program execution. Can't proceed.");
}

if (!is_writable($dir)) {
	die("Error: current directory is not writeable. Can't proceed.");
}

$res = '';
$file = $url;
$file = trim($file);
$file = basename($file); // only filename
$file = preg_replace('#\?.*#si', '', $file); // no params/query string info
$file = preg_replace('#\.\.+#si', '', $file); // no ..
$file = trim($file, '/' ); // just in case

$url = trim($url);
$uniq_id = 'orb_dl_' . sha1($url);
$log_file = "$dir/$uniq_id.log";
$target_file = "$dir/" . (empty($file) ? $uniq_id : $file);

echo "<pre>";

if (file_exists($log_file)) {
	$res .= "There's a download for this file.";
	$res .= file_get_contents($log_file);
} else {
	$url_esc = escapeshellarg( $url );
	$log_file_esc = escapeshellarg($log_file);
	$target_file_esc = escapeshellarg($target_file);
	$res .= "will save the file in [$target_file]\n";
	// options:
	// -b continue in background
	// -c resume download (if it was interrupted before)
	// -d debug log
	// -O target file
	// 2>&1 redirects error messages
	$res = `wget -O $target_file_esc -bcd $url_esc -o $log_file_esc 2>&1`;
}

echo $res;

echo "</pre>";

exit(0);

Configure the dl.php script and when you run it you will see this message.

Continuing in background, pid 21338.

Note: the script will work if shell_exec function is NOT blocked by your hosting provider AND the server is running Linux operating system.

Here's a video explanation about this post.