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

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -