} else { header("HTTP/1.0 404 Not Found"); } } // loop through files and move the chunks to a temporarily created directory if (!empty($_FILES)) { foreach ($_FILES as $file) { // check the error status if ($file['error'] != 0) { _log('error ' . $file['error'] . ' in file ' . $_POST['resumableFilename']); continue; } // init the destination file (format <filename.ext>.part<#chunk> // the file is stored in a temporary directory if (isset($_POST['resumableIdentifier']) && trim($_POST['resumableIdentifier']) != '') { $temp_dir = TEMP_ROOT_DIR . $_POST['resumableIdentifier']; } $dest_file = $temp_dir . '/' . $_POST['resumableFilename'] . '.part' . $_POST['resumableChunkNumber']; // create the temporary directory if (!is_dir($temp_dir)) { mkdir($temp_dir, 0777, true); } // move the temporary file if (!move_uploaded_file($file['tmp_name'], $dest_file)) { _log('Error saving (move_uploaded_file) chunk ' . $_POST['resumableChunkNumber'] . ' for file ' . $_POST['resumableFilename']); } else { // check if all the parts present, and create the final destination file createFileFromChunks($temp_dir, $_POST['resumableFilename'], $_POST['resumableChunkSize'], $_POST['resumableTotalSize'], $_POST['resumableTotalChunks']); } } }
} fclose($fp); } else { echo "Can't make the destination file :(\n"; //_log('cannot create the destination file'); return false; } // rename the temporary directory (to avoid access from other // concurrent chunks uploads) and than delete it //chmod($temp_dir, 0757); //if (rename($temp_dir, $temp_dir.'_UNUSED')) { // rmdir($temp_dir.'_UNUSED'); //} else { // rmdir($temp_dir); //} } else { echo "Failed first check :(\n"; echo "{$total_files} * {$chunkSize} >= ({$totalSize} - {$chunkSize} + 1)\n"; echo $total_files * $chunkSize . " >= " . ($totalSize - $chunkSize + 1) . "\n"; } } echo "Running!\n"; $arguments = $argv; //$arguments[0] is file name, so you would use arguments[1] --> arguments[4] // createFileFromChunks($arguments[1], $arguments[2], $arguments[3], 1024 * 1 * 1024, $arguments[4]); $nowtime = time(); echo "\ntime elapsed: " . time_elapsed_A($nowtime - $oldtime) . "\n"; echo "\ndone yayyyyyyYYYYYYYYY"; //createFileFromChunks('/tmp/resumable.js', 'test1g.tmp', 1024*1*1024, 1000000); // php ~/resumable_custom/resumable.js/samples/Node.js/combiner.php '/tmp/resumable.js' 'test1g.tmp' resumable-1073741824-test1gtmp
} else { header("HTTP/1.0 404 Not Found"); } } // loop through files and move the chunks to a temporarily created directory if (!empty($_FILES)) { foreach ($_FILES as $file) { // check the error status if ($file['error'] != 0) { _log('error ' . $file['error'] . ' in file ' . $_POST['flowFilename']); continue; } // init the destination file (format <filename.ext>.part<#chunk> // the file is stored in a temporary directory //$temp_dir = '../files/'.$_POST['course_id'].'/'.$_POST['flowIdentifier']; $temp_dir = '../files/' . $_POST['course_id'] . '/temp'; $dest_file = $temp_dir . '/' . $_POST['flowFilename'] . '.part' . $_POST['flowChunkNumber']; $file_dir = '../files/' . $_POST['course_id']; // create the temporary directory if (!is_dir($temp_dir)) { mkdir($temp_dir, 0777, true); } // move the temporary file if (!move_uploaded_file($file['tmp_name'], $dest_file)) { echo 'Error saving (move_uploaded_file) chunk ' . $_POST['flowChunkNumber'] . ' for file ' . $_POST['flowFilename']; } else { // check if all the parts present, and create the final destination file createFileFromChunks($temp_dir, $_POST['flowFilename'], $_POST['flowChunkSize'], $_POST['flowTotalSize']); } } }