[GH-ISSUE #1012] Add date prefix to uploaded files #654

Closed
opened 2026-03-02 16:00:34 +03:00 by kerem · 4 comments
Owner

Originally created by @dotcomUNDERGROUND on GitHub (Apr 7, 2023).
Original GitHub issue: https://github.com/prasathmani/tinyfilemanager/issues/1012

I wish to auto add a date prefix to uploaded file names.

Like "DSC_1234.jpg" becomes "2023-04-08 DSC_1234.jpg"

How can I modify the code to achieve this?

Originally created by @dotcomUNDERGROUND on GitHub (Apr 7, 2023). Original GitHub issue: https://github.com/prasathmani/tinyfilemanager/issues/1012 I wish to auto add a date prefix to uploaded file names. Like "DSC_1234.jpg" becomes "2023-04-08 DSC_1234.jpg" How can I modify the code to achieve this?
kerem closed this issue 2026-03-02 16:00:35 +03:00
Author
Owner

@prasathmani commented on GitHub (Apr 8, 2023):

github.com/prasathmani/tinyfilemanager@6a6eb8abec/tinyfilemanager.php (L938)

// format the date as required
$tmp_name = new DateTime().$f['file']['tmp_name'];
<!-- gh-comment-id:1500783121 --> @prasathmani commented on GitHub (Apr 8, 2023): https://github.com/prasathmani/tinyfilemanager/blob/6a6eb8abecef523aafda0e9aa71f94f231128222/tinyfilemanager.php#L938 ```php // format the date as required $tmp_name = new DateTime().$f['file']['tmp_name'];
Author
Owner

@dotcomUNDERGROUND commented on GitHub (Apr 8, 2023):

Thanks!

I tried this:

$tmp_name = $f['file']['tmp_name'];
$date = date("Y-m-d H.i.s");
$tmp_name = "{$date} {$tmp_name}";

But it's not working

<!-- gh-comment-id:1500970556 --> @dotcomUNDERGROUND commented on GitHub (Apr 8, 2023): Thanks! I tried this: ``` $tmp_name = $f['file']['tmp_name']; $date = date("Y-m-d H.i.s"); $tmp_name = "{$date} {$tmp_name}"; ``` But it's not working
Author
Owner

@ner00 commented on GitHub (Apr 10, 2023):

Apparently it doesn't work because it uses $fullPath instead to rename the temporary filename, change this:

github.com/prasathmani/tinyfilemanager@6a6eb8abec/tinyfilemanager.php (L1000)
to:

rename("{$fullPath}.part", dirname($fullPath).$ds.date("Y-m-d H.i.s")." $filename");
<!-- gh-comment-id:1502128346 --> @ner00 commented on GitHub (Apr 10, 2023): Apparently it doesn't work because it uses `$fullPath` instead to rename the temporary filename, change this: https://github.com/prasathmani/tinyfilemanager/blob/6a6eb8abecef523aafda0e9aa71f94f231128222/tinyfilemanager.php#L1000 to: ```php rename("{$fullPath}.part", dirname($fullPath).$ds.date("Y-m-d H.i.s")." $filename"); ```
Author
Owner

@dotcomUNDERGROUND commented on GitHub (Apr 10, 2023):

Worked!

Thank you!

<!-- gh-comment-id:1502187608 --> @dotcomUNDERGROUND commented on GitHub (Apr 10, 2023): Worked! Thank you!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tinyfilemanager#654
No description provided.