public function postUpload()
 {
     if (Input::hasFile('file')) {
         $file = Input::file('file');
         // query uploaded file
         //
         $filename = $file->getClientOriginalName();
         $path = $file->getRealPath();
         $extension = $file->getClientOriginalExtension();
         $mime = $file->getMimeType();
         $size = $file->getSize();
         // replace spaces in filename with dashes
         //
         $filename = Filename::sanitize($filename);
         // move file to destination
         //
         // $destinationFolder = str_random(8);
         $destinationFolder = GUID::create();
         $destinationPath = '/swamp/incoming/' . $destinationFolder;
         $uploadSuccess = Input::file('file')->move($destinationPath, $filename);
         if ($uploadSuccess) {
             return Response::make(array('uploaded_file' => $filename, 'path' => $path, 'extension' => $extension, 'mime' => $mime, 'size' => $size, 'destination_path' => $destinationFolder), 200);
         } else {
             return Response::make('Error moving uploaded file.', 400);
         }
     } else {
         return Response::make('No uploaded file.', 404);
     }
 }
 private function upload($file, $external_url = false)
 {
     $filename = null;
     $path = null;
     $extension = null;
     $mime = null;
     $size = 0;
     $workdir = false;
     // If the file is located externally, retrieve it
     //
     if ($external_url) {
         $workdir = '/tmp/' . uniqid();
         $external_url = escapeshellcmd($external_url);
         // In the future, replace this with a method to
         // pull repositories as needed.
         //
         $result = `mkdir {$workdir};\n\t\t\t cd {$workdir};\n\t\t\t git clone {$external_url}`;
         $files = scandir($workdir);
         if (sizeof($files) !== 3) {
             `rm -rf {$workdir};`;
             return Response::make('Not a single directory.', 404);
         }
         `tar -zcf {$workdir}/{$files['2']}.tar.gz -C {$workdir}/{$files['2']} .`;
         if (!file_exists("{$workdir}/{$files['2']}.tar.gz")) {
             return Response::make('Unable to tar project directory', 404);
         }
         $filename = Filename::sanitize($files[2]) . '.tar.gz';
         $path = "{$workdir}/{$files['2']}.tar.gz";
         $extension = 'tar.gz';
         $mime = 'applization/x-gzip';
         $size = filesize("{$workdir}/{$files['2']}.tar.gz");
         // move file to destination
         //
         // $destinationFolder = str_random(8);
         $destinationFolder = GUID::create();
         $destinationPath = PackageVersion::$incoming . $destinationFolder;
         `mkdir -p {$destinationPath}`;
         `mv {$workdir}/{$files['2']}.tar.gz {$destinationPath}/{$filename}`;
         $uploadSuccess = file_exists("{$destinationPath}/{$filename}");
     } else {
         // query uploaded file
         //
         $filename = $file->getClientOriginalName();
         $path = $file->getRealPath();
         $extension = $file->getClientOriginalExtension();
         $mime = $file->getMimeType();
         $size = $file->getSize();
         // replace spaces in filename with dashes
         //
         $filename = Filename::sanitize($filename);
         // replace extension with original extension
         //
         if ($extension && $extension != '') {
             $filename = pathinfo($filename, PATHINFO_FILENAME) . '.' . $extension;
         }
         // move file to destination
         //
         // $destinationFolder = str_random(8);
         $destinationFolder = GUID::create();
         $destinationPath = PackageVersion::$incoming . $destinationFolder;
         $uploadSuccess = $file->move($destinationPath, $filename);
     }
     if ($workdir) {
         `rm -rf {$workdir}`;
     }
     if ($uploadSuccess) {
         return array('uploaded_file' => $filename, 'path' => $path, 'extension' => $extension, 'mime' => $mime, 'size' => $size, 'destination_path' => $destinationFolder);
     } else {
         return Response::make("Could not upload file.", 500);
     }
 }