Adsy2010
Adsy2010

Reputation: 545

Time Stamp Filename plus File extension

I am creating an upload script for images and have a working script although its a mess.

I am looking to see if there is a simpler way to streamline the method I am using to create a timestamped file name.

This is the code I have:

$mkfilename = time() . end(explode(".", strtolower($_FILES['pic']['name'])));

This is the most streamlined function I have been able to come up with so far, its just ugly on the function front. I'm sure there's a better way to do it.

Upvotes: 0

Views: 1839

Answers (1)

florian h
florian h

Reputation: 1171

Not much to improve:

$mkfilename = time() . strrchr(strtolower($_FILES['pic']['name']), '.');

Not relevant for your question, but keep in mind that using only time() will conflict when two files are uploaded in the same second. Maybe you want to use like a hash function over time and filename.

Upvotes: 1

Related Questions