file storage - Laravel 5.2 filename appending index number -
i have simple dilema using laravel 5.2. want store files in directories. there 2 steps need do:
- check if filename not taken already.
- if filename taken, append index number dash filename:
"_1"
if "_1"
taken, filename should append "_2"
etc.
how can this?
just use simple loop:
$file_name = "file"; $ext = "jpg"; $i = 0; $original_file_name = $file_name while (file_exists("{$file_name}.{$ext}")) { $i++; $file_name = $original_file_name . '_' . $i; }
Comments
Post a Comment