public function upload(Request $request)
 {
     // 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) {
                 $this->_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 = public_path() . '/temp/' . $_POST['flowIdentifier'];
             $dest_file = $temp_dir . '/' . $_POST['flowFilename'] . '.part' . $_POST['flowChunkNumber'];
             // 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)) {
                 $this->_log('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
                 $this->createFileFromChunks($temp_dir, $_POST['flowFilename'], $_POST['flowChunkSize'], $_POST['flowTotalSize']);
                 if ($request->input('mode') == "register") {
                     $user = User::find($request->input('id'));
                     $user->pictureDist = 'temp/' . $_POST['flowFilename'];
                     $user->update();
                 } else {
                     if ($request->input('mode') == "activity") {
                         $activity = Activity::find($request->input('id'));
                         $activity->pictureDist = 'temp/' . $_POST['flowFilename'];
                         $activity->update();
                     } else {
                         if ($request->input('mode') == "task") {
                             $activity = TaskList::find($request->input('id'));
                             $activity->pictureLocation = 'temp/' . $_POST['flowFilename'];
                             $activity->update();
                         }
                     }
                 }
             }
         }
     }
     ////////////////////////////////////////////////////////////////////
     // THE SCRIPT
     ////////////////////////////////////////////////////////////////////
     //check if request is GET and the requested chunk exists or not. this makes testChunks work
     if ($_SERVER['REQUEST_METHOD'] === 'GET') {
         $temp_dir = 'temp/' . $_GET['flowIdentifier'];
         $chunk_file = $temp_dir . '/' . $_GET['flowFilename'] . '.part' . $_GET['flowChunkNumber'];
         if (file_exists($chunk_file)) {
             header("HTTP/1.0 200 Ok");
         } else {
             header("HTTP/1.0 404 Not Found");
         }
     }
 }
示例#2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     if ($id == null) {
         return response("fail", 500);
     }
     $taskList = TaskList::find($id);
     $taskList->activityType()->detach();
     $taskList->workerMember()->detach();
     $taskList->delete();
     return response("success", 200);
 }