JREAM Posted June 9, 2009 Share Posted June 9, 2009 This is working good, but i got it doing this, 1st file duplicate: file_0.txt 2nd file duplicate: file_0_1.txt I wanted it to just change the #, file_0 to file_1, not add the additional _0_1_2 etc.. $var = 0; for ($i = 0; $i < 1; $i++) { if (file_exists($upload_path . $filename)) { // Split Extension $split = split('[/\\.]', $filename); // Grab Pieces $f_name = $split[0]; $f_ext = substr($filename, strrpos($filename, '.') + 1); $filename = $f_name ."_$var.". $f_ext; $var++; $i--; } } Link to comment https://forums.phpfreaks.com/topic/161565-solved-file-renaming-kinda-easy-but-im-stuck/ Share on other sites More sharing options...
gevans Posted June 9, 2009 Share Posted June 9, 2009 change $filename = $f_name ."_$var.". $f_ext; to $filname_array = explode("_", $f_name); $filename = $filename_array[0] ."_$var.". $f_ext; Link to comment https://forums.phpfreaks.com/topic/161565-solved-file-renaming-kinda-easy-but-im-stuck/#findComment-852582 Share on other sites More sharing options...
waynew Posted June 9, 2009 Share Posted June 9, 2009 Replied to wrong topic. Link to comment https://forums.phpfreaks.com/topic/161565-solved-file-renaming-kinda-easy-but-im-stuck/#findComment-852604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.