Skip to content

Instantly share code, notes, and snippets.

@snowman-repos
Created October 2, 2012 08:37
Show Gist options
  • Save snowman-repos/3817385 to your computer and use it in GitHub Desktop.
Save snowman-repos/3817385 to your computer and use it in GitHub Desktop.

Revisions

  1. Darryl Snow renamed this gist Oct 5, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Darryl Snow created this gist Oct 2, 2012.
    19 changes: 19 additions & 0 deletions gistfile1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    function file_newname($path, $filename){
    if ($pos = strrpos($filename, '.')) {
    $name = substr($filename, 0, $pos);
    $ext = substr($filename, $pos);
    } else {
    $name = $filename;
    }

    $newpath = $path.'/'.$filename;
    $newname = $filename;
    $counter = 0;
    while (file_exists($newpath)) {
    $newname = $name .'_'. $counter . $ext;
    $newpath = $path.'/'.$newname;
    $counter++;
    }

    return $newname;
    }