Tag Archives: Php

A Simple Server-to-Server File Transfer Script (PHP)

I’ve used this little script quite a bit while moving servers, and it’s saved me tons of time. It allows you to transfer large files from one server to another by breaking up the file into 1MB pieces to avoid memory limits. There seems to be a 2GB maximum on transfer sizes.

To use it, simply change the variable $path to a relative path on your new server where you want the file to be saved to, change the variable $url to the web-accessible location of the file on the old server, and upload and run the script on your new server.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
set_time_limit(0); //Unlimited max execution time
 
$path = 'newfile.zip';
$url = 'http://example.com/oldfile.zip';
$newfname = $path;
echo 'Starting Download!<br>';
$file = fopen ($url, "rb");
if($file) {
	$newf = fopen ($newfname, "wb");
	if($newf)
		while(!feof($file)) {
			fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
			echo '1 MB File Chunk Written!<br>';
		}
}
if($file) {
	fclose($file);
}
if($newf) {
	fclose($newf);
}
echo 'Finished!';
?>