@@ -128,13 +128,17 @@ public function fetchProperties(array $config = null)
128
128
* @param int $length
129
129
* @return string
130
130
*/
131
- protected function generateRandomName (int $ length = 15 )
131
+ protected function generateRandomName (int $ length = 20 )
132
132
{
133
+ $ counter = 1 ;
133
134
do {
134
- $ randomName = Str::random ($ length );
135
+ $ randomName = str_replace ( ' . ' , '' , Str::random ($ length) );
135
136
$ check = File::query ()
136
137
->where ("name " , $ randomName )
137
138
->first ();
139
+ if ($ counter > 5 )
140
+ throw new \Exception ("Too much effort to select the file name. " );
141
+ $ counter ++;
138
142
} while (!empty ($ check ));
139
143
140
144
return $ randomName ;
@@ -150,6 +154,7 @@ protected function generateRandomName(int $length = 15)
150
154
public function useFileNameToUpload ($ status = true )
151
155
{
152
156
$ this ->useFileNameToUpload = $ status ;
157
+
153
158
return $ this ;
154
159
}
155
160
@@ -164,9 +169,9 @@ public function useFileNameToUpload($status = true)
164
169
*/
165
170
public function upload ($ file )
166
171
{
167
- $ nameSplit = explode ( ' . ' , $ file ->getClientOriginalName () );
168
- $ fileName = $ nameSplit [ 0 ] ;
169
- $ format = $ nameSplit [ 1 ] ;
172
+ $ fileInfo = $ file ->getClientOriginalName ();
173
+ $ fileName = pathinfo ( $ fileInfo , PATHINFO_FILENAME ) ;
174
+ $ format = $ file -> getClientOriginalExtension () ;
170
175
if (!$ this ->getName ()) {
171
176
if ($ this ->useFileNameToUpload ) {
172
177
$ this ->setName ($ fileName );
@@ -198,6 +203,7 @@ protected function createFileRow($name = null)
198
203
"private " => $ this ->public ? false : true ,
199
204
]);
200
205
$ this ->setFile ($ file );
206
+
201
207
return $ file ;
202
208
}
203
209
@@ -232,6 +238,7 @@ public function getFile($name = null)
232
238
public function setFile (File $ file )
233
239
{
234
240
$ this ->file = $ file ;
241
+
235
242
return $ this ;
236
243
}
237
244
@@ -279,6 +286,7 @@ abstract protected function handleDelete(File $file);
279
286
public function setConfig (array $ config )
280
287
{
281
288
$ this ->config = $ config ;
289
+
282
290
return $ this ;
283
291
}
284
292
@@ -302,6 +310,7 @@ public function getConfig($name = null)
302
310
if (is_null ($ name )) return $ config ;
303
311
$ find = $ config [$ name ];
304
312
if (!isset ($ find )) return false ;
313
+
305
314
return $ find ;
306
315
}
307
316
@@ -316,6 +325,7 @@ public function getConfig($name = null)
316
325
public function setType ($ type )
317
326
{
318
327
$ this ->type = $ type ;
328
+
319
329
return $ this ;
320
330
}
321
331
@@ -340,6 +350,7 @@ public function getType()
340
350
public function setPath ($ path )
341
351
{
342
352
$ this ->path = $ path ;
353
+
343
354
return $ this ;
344
355
}
345
356
@@ -403,6 +414,7 @@ public function getUploadPath()
403
414
public function dateTimePrefix ($ value = true )
404
415
{
405
416
$ this ->dateTimePrefix = $ value ;
417
+
406
418
return $ this ;
407
419
}
408
420
@@ -427,6 +439,7 @@ public function getPrefix()
427
439
public function setPrefix ($ prefix )
428
440
{
429
441
$ this ->prefix = $ prefix ;
442
+
430
443
return $ this ;
431
444
}
432
445
@@ -444,6 +457,7 @@ protected function getStorageFolder($src)
444
457
return storage_path ($ src );
445
458
if ($ this ->storageFolder == "public " )
446
459
return public_path ($ src );
460
+
447
461
return public_path ($ src );
448
462
}
449
463
@@ -457,6 +471,7 @@ protected function getStorageFolder($src)
457
471
public function setName (string $ name )
458
472
{
459
473
$ this ->name = $ name ;
474
+
460
475
return $ this ;
461
476
}
462
477
@@ -482,6 +497,7 @@ public function getName()
482
497
public function setFormat (string $ format )
483
498
{
484
499
$ this ->format = $ format ;
500
+
485
501
return $ this ;
486
502
}
487
503
@@ -508,6 +524,7 @@ public function isPrivate()
508
524
{
509
525
$ this ->storageFolder = "storage " ;
510
526
$ this ->public = false ;
527
+
511
528
return $ this ;
512
529
}
513
530
@@ -523,6 +540,7 @@ public function isPublic()
523
540
{
524
541
$ this ->storageFolder = "public " ;
525
542
$ this ->public = true ;
543
+
526
544
return $ this ;
527
545
}
528
546
0 commit comments