Skip to content

Commit 52ca3c9

Browse files
committed
Bug fix for set an unique name of uploading file
1 parent bdc0b67 commit 52ca3c9

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ To work with Amazon it uses [AWS SDK](https://github.com/aws/aws-sdk-php).
3838

3939
Via composer:
4040

41-
```composer require itstructure/yii2-multi-format-uploader ^2.1.2```
41+
```composer require itstructure/yii2-multi-format-uploader ^2.1.3```
4242

4343
or in section **require** of composer.json file set the following:
4444
```
4545
"require": {
46-
"itstructure/yii2-multi-format-uploader": "^2.1.2"
46+
"itstructure/yii2-multi-format-uploader": "^2.1.3"
4747
}
4848
```
4949
and command ```composer install```, if you install yii2 project extensions first,

changelog.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
### CHANGE LOG:
22

3+
**2.1.3 August 19, 2019:**
4+
- Bug fix for set an unique name of uploading file. Used **microtime()** in ```LocalUpload``` and ```S3Upload``` models.
5+
36
**2.1.2 June 12, 2019:**
47
- Optimize getting module object from a mediafile in **getModule()** function.
58

@@ -8,8 +11,8 @@
811
Used in **getPreviewOptions()** module method if **is_callable($previewOptions[$location])**.
912

1013
**2.1.0 May 18, 2019:**
11-
- Add urlPrefix parameter in to AlbumController for redirect and view links.
12-
- Add urlPrefixNeighbor parameter in to AlbumController for view links of neighbor entity.
14+
- Add **urlPrefix parameter** in to ```AlbumController``` for redirect and view links.
15+
- Add **urlPrefixNeighbor** parameter in to ```AlbumController``` for view links of neighbor entity.
1316

1417
**2.0.1 August 9, 2018:**
1518
- Delete duplicates and optimize code.
@@ -21,7 +24,7 @@
2124
- Renaming controllers and models to a single entity name.
2225
- Renaming module constants.
2326
- Some simple code fixes.
24-
- Add file_exists() check function in to sendFile() of the LocalUpload model.
27+
- Add **file_exists()** check function in to **sendFile()** of the ```LocalUpload``` model.
2528
- Fixes for README.
2629

2730
**1.0.0 May 15, 2018:**

src/models/upload/LocalUpload.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,18 @@ protected function setParamsForSend(): void
8383

8484
if (!empty($this->subDir)) {
8585
$uploadDir = $uploadDir .
86-
DIRECTORY_SEPARATOR .
87-
trim(trim($this->subDir, '/'), '\\');
86+
DIRECTORY_SEPARATOR .
87+
trim(trim($this->subDir, '/'), '\\');
8888
}
8989

9090
$this->uploadDir = $uploadDir .
91-
DIRECTORY_SEPARATOR . substr(md5(time()), 0, self::DIR_LENGTH_FIRST) .
92-
DIRECTORY_SEPARATOR . substr(md5(time()+1), 0, self::DIR_LENGTH_SECOND);
91+
DIRECTORY_SEPARATOR . substr(md5(time()), 0, self::DIR_LENGTH_FIRST) .
92+
DIRECTORY_SEPARATOR . substr(md5(microtime().$this->file->tempName), 0, self::DIR_LENGTH_SECOND);
9393

9494
$this->uploadPath = $this->uploadRoot . DIRECTORY_SEPARATOR . $this->uploadDir;
9595

9696
$this->outFileName = $this->renameFiles ?
97-
md5(time()+2).'.'.$this->file->extension :
97+
md5(md5(microtime()).$this->file->tempName).'.'.$this->file->extension :
9898
Inflector::slug($this->file->baseName).'.'. $this->file->extension;
9999

100100
$this->databaseUrl = DIRECTORY_SEPARATOR . $this->uploadDir . DIRECTORY_SEPARATOR . $this->outFileName;

src/models/upload/S3Upload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ protected function setParamsForSend(): void
158158

159159
$this->uploadDir = $uploadDir .
160160
self::BUCKET_DIR_SEPARATOR . substr(md5(time()), 0, self::DIR_LENGTH_FIRST) .
161-
self::BUCKET_DIR_SEPARATOR . substr(md5(time()+1), 0, self::DIR_LENGTH_SECOND);
161+
self::BUCKET_DIR_SEPARATOR . substr(md5(microtime().$this->file->tempName), 0, self::DIR_LENGTH_SECOND);
162162

163163
$this->outFileName = $this->renameFiles ?
164-
md5(time()+2).'.'.$this->file->extension :
164+
md5(md5(microtime()).$this->file->tempName).'.'.$this->file->extension :
165165
Inflector::slug($this->file->baseName).'.'. $this->file->extension;
166166

167167
$this->bucketForUpload = null !== $this->owner && isset($this->s3Buckets[$this->owner]) ?

0 commit comments

Comments
 (0)