I created a script that gets a MP3 file from a GET statement. I need a way to make sure that if the original name "recording.mp3" does not exist then create it from GET contents, if it does exist then append a number to the file name. What am I doing wrong? the part that does not work thus far is appending the number but getting the file and saving works great. Remove the while loop and program works!
<?php
$actual_name = pathinfo("PHPAPI/recording.mp3",PATHINFO_FILENAME);
$original_name = $actual_name;
$extension = pathinfo("PHPAPI/recording.mp3",PATHINFO_EXTENSION);
$i = 0;
if ($_GET["RecordingUrl"]){
while(file_exists("PHPAPI/".$actual_name.".".$extension)){
$actual_name = $original_name.$i;
$name = $actual_name.".".$extension;
$i++;
}
file_put_contents($name, file_get_contents($_GET["RecordingUrl"]));
}
elseif ($_GET["RecordingUrl"]){
file_put_contents($original_name.".".$extension,
file_get_contents($_GET["RecordingUrl"]));
}
?>