HomePHP Page 4 - Merging a File Split for FTP Upload using PHP
Implementation of the File Merging Script - PHP
This is the second part of a tutorial on file splitting during an FTP upload. In this part, you will learn the details of file merging and implementation. The split PHP script was thoroughly discussed in the first part. It is highly recommended that you read that part to easily understand this one.
To implement this file merging script you need to upload it to the FTP server. You can download the complete PHP file merging script. Or copy and paste the code in the previous section to a notepad file and save as “mergethisfile.php.”
Below are the steps necessary to implement the file merging process:
Step 1: Create a folder name “merge.” This folder can be placed in your desktop.
Step 2: Copy all the split parts (created in XAMPP local host folder) to this folder. If you have 12 parts (those with file name, splited_0, splited_1, etc as shown in the previous example), copy them to this folder.
Step 3: Copy the “mergethisfile.php” to the merge folder.
Step 4: Open your favorite FTP client. Upload each part (the split parts and the FTP folder) to the desired location in the FTP server. If there are 12 parts, there will be 12 upload sessions, with each upload size at 258 KB (using the example above; each part is less than the 500 KB maximum size upload limit).
For example, I would like to upload this inside the “mp3” directory. The screenshot below shows an example of the file parts and the mergethisfile.php script after uploading in the FTP server. It also shows the screenshot after merging and files parts deletion (details below):
Step 5: In your browser address bar, type the path of the mergethisfile.php and press enter. Here is an example (using the illustrations above):
A web form will be shown. Type the details as accurately as possible. Since test.mp3 (the example in this article) was split into 12 parts (see results in the previous section), you need to enter 12 in the “Enter the number of splitted parts” field; see screenshot below:
After filling in the information, click “Merge this file.”
The merged file will now be created in the directory, and you can safely delete the parts as well as the merge script. The result is a single file, which is “test.mp3” (see related screenshots above).