Ejemplo n.º 1
2
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['file' => 'required']);
     $file = $request->file('file');
     $original_file_name = $file->getClientOriginalName();
     $file_name = pathinfo($original_file_name, PATHINFO_FILENAME);
     $extension = \File::extension($original_file_name);
     $actual_name = $file_name . '.' . $extension;
     $apk = new \ApkParser\Parser($file);
     $manifest = $apk->getManifest();
     $labelResourceId = $apk->getManifest()->getApplication()->getLabel();
     $appLabel = $apk->getResources($labelResourceId);
     $package_name = $manifest->getPackageName();
     if (Apk::packageExist($package_name)) {
         Session::flash('flash_class', 'alert-danger');
         Session::flash('flash_message', 'Apk namespace already exist.');
         return redirect()->route("apk.create");
     }
     Apk::create(array('app_name' => $appLabel[0], 'pkgname' => $package_name, 'version' => $manifest->getVersionCode(), 'version_name' => $manifest->getVersionName(), 'md5' => md5_file($file), 'filename' => $actual_name, 'filesize' => str_format_filesize(\File::size($file)), 'token' => md5(uniqid(mt_rand(), true))));
     $folderpath = base_path() . '/storage/apk/' . $manifest->getPackageName();
     if (!\File::exists($folderpath)) {
         \File::makeDirectory($folderpath);
     }
     $file_path = $request->file('file')->move($folderpath, $actual_name);
     return redirect()->route("apk.index");
 }
Ejemplo n.º 2
0
 public function testStrFormatFilesize()
 {
     // bytes
     $this->assertEquals('10.00 bytes', str_format_filesize(10));
     $this->assertEquals('100.00 bytes', str_format_filesize(100));
     $this->assertEquals('1000.00 bytes', str_format_filesize(1000));
     // KB
     $this->assertEquals('9.77 KB', str_format_filesize(10000));
     $this->assertEquals('97.66 KB', str_format_filesize(100000));
     $this->assertEquals('976.56 KB', str_format_filesize(1000000));
     // MB
     $this->assertEquals('9.54 MB', str_format_filesize(10000000));
     $this->assertEquals('95.37 MB', str_format_filesize(100000000));
     $this->assertEquals('953.67 MB', str_format_filesize(1000000000));
     // GB
     $this->assertEquals('9.31 GB', str_format_filesize(10000000000));
     $this->assertEquals('93.13 GB', str_format_filesize(100000000000));
     $this->assertEquals('931.32 GB', str_format_filesize(1000000000000));
     // TB
     $this->assertEquals('9.09 TB', str_format_filesize(10000000000000));
     $this->assertEquals('90.95 TB', str_format_filesize(100000000000000));
     $this->assertEquals('909.49 TB', str_format_filesize(1000000000000000));
     // PB
     $this->assertEquals('8.88 PB', str_format_filesize(10000000000000000));
     $this->assertEquals('88.82 PB', str_format_filesize(100000000000000000));
     $this->assertEquals('888.18 PB', str_format_filesize(1000000000000000000));
 }