public function file(Silex\Application $app) { $request = new \Flow\Request(); $chunkNumber = $request->getCurrentChunkNumber() ?: 0; $chunkSize = $request->getDefaultChunkSize() ?: 0; $totalSize = $request->getTotalSize() ?: 0; $identifier = $request->getIdentifier() ?: ''; $filename = $request->getFileName() ?: ''; $files = $request->getFile(); if (!$files || !$files['size']) { utils::log('invalid_flow_request'); return new Response('', Response::HTTP_OK, ['Content-Type' => 'text/plain']); } $original_filename = $files['name']; //['originalFilename'] ; $validation = $this->validateRequest($chunkNumber, $chunkSize, $totalSize, $identifier, $filename, $files['size']); if ($validation !== 'valid') { utils::log($validation); return new Response('', Response::HTTP_OK, ['Content-Type' => 'text/plain']); } $chunkFilename = $this->getChunkFilename($chunkNumber, $identifier); // Save the chunk //$fs =new Filesystem () ; //$fs->rename ($files ['tmp_name'], $chunkFilename, true) ; move_uploaded_file($files['tmp_name'], $chunkFilename); // Do we have all the chunks? $currentTestChunk = 1; //$numberOfChunks =max (intval (floor ($totalSize / ($chunkSize * 1.0))), 1) ; $numberOfChunks = $request->getTotalChunks(); for (; $currentTestChunk <= $numberOfChunks; $currentTestChunk++) { if (!utils::realpath($this->getChunkFilename($currentTestChunk, $identifier))) { break; } } if ($currentTestChunk > $numberOfChunks) { // done utils::log("POST done {$original_filename} {$identifier}"); $data = (object) array('key' => $identifier, 'name' => $original_filename, 'size' => $totalSize, 'bytesRead' => $totalSize, 'bytesPosted' => 0); $path = $app->dataDir("/{$identifier}.json"); if (file_put_contents($path, json_encode($data)) === false) { utils::log("Could not save {$path}"); } $path = $app->tmpDir("/{$original_filename}"); $this->save($path, $request); // var st =fs.createWriteStream ('./tmp/' + original_filename) // .on ('finish', function () {}) ; // flow.write (identifier, st, { // end: true, // onDone: function () { // flow.clean (identifier) ; // } // }) ; } else { // partly_done utils::log("POST partly_done {$original_filename} {$identifier}"); } //if ( ACCESS_CONTROLL_ALLOW_ORIGIN ) // return (new Response ('', Response::HTTP_OK, [ 'Access-Control-Allow-Origin' => '*', Content-Type' => 'text/plain' ])) ; return new Response('', Response::HTTP_OK, ['Content-Type' => 'text/plain']); }