How do I check if file name exists, rename the file?
for example, I upload a image 1086_002.jpg if the file exists, rename the file as 1086_0021.
1086_002.jpg
1086_0021.
Try something like:
$fullpath = 'images/1086_002.jpg'; $additional = '1'; while (file_exists($fullpath)) { $info = pathinfo($fullpath); $fullpath = $info['dirname'] . '/' . $info['filename'] . $additional . '.' . $info['extension']; }