2
2
3
3
namespace Statamic \Assets ;
4
4
5
- use Carbon \Carbon ;
6
5
use Stringy \Stringy ;
7
6
use Statamic \API \Str ;
8
7
use Statamic \API \URL ;
12
11
use Statamic \API \Image ;
13
12
use Statamic \Data \Data ;
14
13
use Statamic \API \Blueprint ;
14
+ use Illuminate \Support \Carbon ;
15
15
use Statamic \Data \ContainsData ;
16
16
use League \Flysystem \Filesystem ;
17
17
use League \Flysystem \Adapter \Local ;
@@ -421,18 +421,15 @@ public function upload(UploadedFile $file)
421
421
422
422
// If the file exists, we'll append a timestamp to prevent overwriting.
423
423
if ($ this ->disk ()->exists ($ path )) {
424
- $ basename = $ filename . '- ' . time () . '. ' . $ ext ;
424
+ $ basename = $ filename . '- ' . Carbon:: now ()-> timestamp . '. ' . $ ext ;
425
425
$ path = Str::removeLeft (Path::assemble ($ directory , $ basename ), '/ ' );
426
426
}
427
427
428
- $ this ->performUpload ( $ file , $ path );
428
+ $ this ->disk ()-> put ( $ path , $ file );
429
429
430
430
$ this ->path ($ path );
431
431
432
432
event (new AssetUploaded ($ this ));
433
-
434
- // Legacy/Deprecated. TODO: Remove in 2.3
435
- event ('asset.uploaded ' , $ path );
436
433
}
437
434
438
435
private function getSafeFilename ($ string )
@@ -451,36 +448,6 @@ private function getSafeFilename($string)
451
448
return (string ) $ str ;
452
449
}
453
450
454
- /**
455
- * Actually perform the file upload.
456
- *
457
- * Saves the file to a temporary location on the local filesystem, then moves it to the
458
- * right place. This is a workaround for needing to know the file extension or mime
459
- * type when uploading to Amazon S3. Temporary files don't have file extensions
460
- * so sending directly to S3 causes it to appear with the wrong mime type.
461
- *
462
- * @param UploadedFile $file
463
- * @param string $path
464
- * @return void
465
- */
466
- private function performUpload (UploadedFile $ file , $ path )
467
- {
468
- // Build up a path where the file will be temporarily stored
469
- $ temp = 'uploads/ ' .md5 ($ file ->getRealPath ().microtime (true )).'. ' .$ file ->getClientOriginalExtension ();
470
-
471
- // Upload to a temporary location
472
- $ temp_disk = new Filesystem (new Local (temp_path ()));
473
- $ stream = fopen ($ file ->getRealPath (), 'r+ ' );
474
- $ temp_disk ->putStream ($ temp , $ stream );
475
- fclose ($ stream );
476
-
477
- // Move from the temporary location to the real container location
478
- $ this ->disk ()->put ($ path , $ temp_disk ->readStream ($ temp ));
479
-
480
- // Delete the temporary file
481
- $ temp_disk ->delete ($ temp );
482
- }
483
-
484
451
/**
485
452
* Replace the file
486
453
*
0 commit comments