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:

  1. check if filename not taken already.
  2. 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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -