Home arrow PHP arrow Page 3 - How to Split a File During an FTP Upload Using PHP

PHP File Splitting Script: splitthisfile.php - PHP

One of the known limitations of free hosting packages is the file upload limit. For example, some hosting companies set an upload limit of 500 KB. This means that for any uploads to the FTP server, the file should not be more than 500 KB or else the server won’t accept it and you will not be able to upload your file. Fortunately, by splitting your files, you can get around this limitation; this two-part tutorial series will show you how.

TABLE OF CONTENTS:
  1. How to Split a File During an FTP Upload Using PHP
  2. Inside the Split Folder Directory
  3. PHP File Splitting Script: splitthisfile.php
  4. Using the File Splitting Function
By: Codex-M
Rating: starstarstarstarstar / 3
November 17, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The first step is to show a web form that accepts the file name to be split and the maximum file upload limit size in kilobytes. The second step should be to receive the POST data and compute the number of splitting parts. (The complete script will be downloaded/shown in the second part of this tutorial)

The formula for the number of parts into which the file will be split is:

Number of Split Parts (PHP variable: $parts_num) = (File size / Maximum Upload limit) x 2

The script uses a safety factor of two to make sure the resulting file size of the split parts is significantly less than the maximum upload limit of the FTP server. So for example, say the file size to be split is 1.1 MB and the FTP server maximum upload size is 500KB. The number of split parts can be computed like this:

Number of Split Parts (PHP variable: $parts_num) = ((1100KB) / (500KB)) x 2 = 4.4, rounding down to implement a realistic value brings us to four parts.

Since 1.1MB cannot be uploaded at once using a 500 KB upload limit, with four parts the file size per upload will be reduced to 1100KB/4 ~ 275KB, which is less than 500KB, but you have to upload each of the parts to the FTP server.

In PHP the file size can be measured by:

$filesize = ((filesize($file_name))/1000);

Using the filesize() function gives the results in bytes, so to convert that to kilobytes, divide the equation by 1000.

Rounding down can be accomplished by a floor() PHP function, so for example to implement rounding down of the number of parts:

$parts_num = floor($parts_num);

Then the split file function (PHP user-defined function splitthisfile()) accepts two inputs, $file_name and $parts_num. A modification script was formulated based on Arash Hemmat's original PHP class.



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: