<?php
/*
--------------------------------------------------
filesplit.php HJSplit compatiple PHP file splitter
--------------------------------------------------
File name:
filesplit.php
Author:
Umit Tirpan 2007-03-22
Author's Website:
http://forum.iyinet.com/
Description:
This PHP script, splits the files into smaller pieces in binary.
It is compatiple with HJSplit, so you can re-join splitted files using HJSplit's Join utility.
It can split a file up to 999 pieces.
What is the use, why will I use this?
Some webmasters do not have shell access to their websites. This prevents them splitting big files, ie. MySQL backups, into smaller files. Splitting a 200Mb file into 10 x 20Mb file may be easy on webmaster to download in pieces.
How to run:
Make sure your webserver has write permission on the target folder.
Edit variables.
Upload (ftp) this file to your webserver.
For security reason, filename is hardcoded. You can modify code to accept $_GET['file']
Run with your favorite browser.
http://www.<your-web-site>.com/filesplit.php
It is Ok to modify this code and use in/with your applications.
*/
// Edit here (3 variables)
// ---------------------------
// File to split, is its not in the same folder with filesplit.php, full path is required.
$file = "http://desi-instincts.com/Games%20(Latest)%20(2007)/GtASa/GTA%20San%20Andreas.part01.exe";
$filename = "GTA-San-Andreas.part01.exe";
// Target folder. Splitted files will be stored here. Original file never gets touched.
// Do not append slash! Make sure webserver has write permission on this folder.
$targetfolder = 'tmp';
// File size in Mb per piece. For a 200Mb file if piecesize=10 it will result with 20 x 10Mb files
$piecesize = 10;
// Do NOT edit under this line
// ---------------------------
$buffer = 1024*8;
$piece = 1048576*$piecesize;
$current = 0;
$splitnum = 1;
if(!$handle = fopen($file, "rb")) {
die("Unable to open $file.<br>Make sure you edited filesplit.php correctly!<br>\n");
}
$piece_name = $targetfolder.'/'.$filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT);
$fw = fopen($piece_name,"w");
echo "Splitting $file into $piecesize Mb files (last piece may be smaller in size) ...<br>\n";
echo "$piece_name <br>\n";
while (!feof($handle)) {
if($current < $piece) {
if(fwrite($fw, fread($handle, $buffer))) {
$current += $buffer;
} else {
die("filesplit.php is unable to write to current folder.<br>I think it does not have write permission!<br>Try chmod +w folder<br>\n");
}
} else {
fclose($fw);
$current = 0;
$splitnum++;
$piece_name = $targetfolder.'/'.$filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT);
echo "$piece_name <br>\n";
$fw = fopen($piece_name,"w");
}
}
fclose($fw);
fclose($handle);
echo "Done! <br>\n"
?>