[ create a new paste ] login | about

Link: http://codepad.org/KNuKds5d    [ raw code | output | fork ]

PHP, pasted on Apr 5:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php

$files = array('images/1086_002.jpg', 'images/1086_0021.jpg', 'images/1086_00211.jpg', 'images/1086_002111.jpg');

$fullpath = 'images/1086_002.jpg';
$additional = '1';

// replaced file_exists with in_array for this example
while (in_array($fullpath, $files)) {
    $info = pathinfo($fullpath);
    $fullpath = $info['dirname'] . '/'
              . $info['filename'] . $additional
              . '.' . $info['extension'];
}

var_dump($fullpath);


Output:
1
string(23) "images/1086_0021111.jpg"


Create a new paste based on this one


Comments: