Skip to content

Commit

Permalink
Update PHP Sample to fix recreating file before file is finished uplo…
Browse files Browse the repository at this point in the history
…ading

A problem was discovered in the PHP sample where the server would start
building the file before all the file’s chunks where received and
therefore corrupted the file. I have edited the code to do a check to
see if the server has the files equal to the size of the file being
uploaded before building the file.
  • Loading branch information
ChadTaljaardt committed Oct 12, 2015
1 parent 57cad1a commit 5c65475
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions samples/Backend on PHP.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,19 @@ function rrmdir($dir) {
function createFileFromChunks($temp_dir, $fileName, $chunkSize, $totalSize) {

// count all the parts of this file
$total_files = 0;
$total_files_on_server_size = 0;
$temp_total = 0;
foreach(scandir($temp_dir) as $file) {
$temp_total = $total_files_on_server_size;
$tempfilesize = filesize($temp_dir.'/'.$file);
$total_files_on_server_size = $temp_total + $tempfilesize;
if (stripos($file, $fileName) !== false) {
$total_files++;
}
}

// check that all the parts are present
// the size of the last part is between chunkSize and 2*$chunkSize
if ($total_files * $chunkSize >= ($totalSize - $chunkSize + 1)) {
// If the Size of all the chunks on the server is equal to the size of the file uploaded.
if ($total_files_on_server_size >= $totalSize) {

// create the final destination file
if (($fp = fopen('temp/'.$fileName, 'w')) !== false) {
Expand Down

0 comments on commit 5c65475

Please sign in to comment.