Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel rename file if exists

function newName2($fullpath) {
  $path = dirname($fullpath);
  if (!file_exists($fullpath)) return $fullpath;
  $fnameNoExt = pathinfo($fullpath,PATHINFO_FILENAME);
  $ext = pathinfo($fullpath, PATHINFO_EXTENSION);

  $i = 1;
  while(file_exists("$path/$fnameNoExt ($i).$ext")) $i++;
  return "$path/$fnameNoExt ($i).$ext";
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #laravel #rename #file #exists
ADD COMMENT
Topic
Name
4+8 =