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.
You can change your if
statement to a while
loop:
$newpath = $fullpath;
while(file_exists($newpath)) {
$newpieces = explode(".", $fullpath);
$frontpath = str_replace('.'.end($newpieces),'',$fullpath);
$newpath = $frontpath.'1.'.end($newpieces);
}
file_put_contents($newpath, file_get_contents($_POST['upload']));