Last active
December 31, 2015 00:09
-
-
Save simkimsia/7905745 to your computer and use it in GitHub Desktop.
How to execute the Keep Both Files operation using PHP. Inspired by http://stackoverflow.com/a/14081609/80353
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// you may also use pathinfo | |
// if the file you want to upload is already in the file directory | |
// but not in the destination folder | |
$file_to_upload = 'test.png'; | |
// either way, you definitely need to retrieve the filename and extension | |
$filename = 'test'; | |
$extension = 'png'; | |
// feel free to change the destination path | |
$destination_path = dirname(__FILE__); | |
// initialize the new filename as the actual name of the file_to_upload | |
$new_filename = $filename; | |
$i=0; | |
while(file_exists($destination_path . DIRECTORY_SEPARATOR . $new_filename . "." . $extension)) | |
{ | |
$new_filename=$filename . " ($i)"; | |
$i++; | |
} | |
$new_file = $new_filename . "." . $extension; | |
echo $new_file; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment