0

How do I add a file extension to this code so its looking for a .zip

So this script works perfectly if i do url.com?sn=123 - it will delete a file called 123, however how do add the .zip in the code so it actually says if file 123.zip exists then unlink 123.zip

<?PHP
 if (file_exists($_GET["sn"])) {
        unlink($_GET["sn"]);
    } else {
        // File not found.
    }

?>

I tried doing this: (however it just errors)

<?PHP
$zip=".zip";
 if (file_exists($_GET['sn'],['zip'])) {
        unlink($_GET['sn'],['zip']);
    } else {
        // File not found.
    }

?>
DML1783
  • 1
  • 1
  • Possible duplicate of [PHP string concatenation](https://stackoverflow.com/questions/11441369/php-string-concatenation) – manveti Jan 05 '19 at 00:38

1 Answers1

0

You could do this:

<?PHP
$file_name = $_GET['sn'].'.zip';
if (file_exists($file_name)) {
    unlink($file_name);
} else {
    // File not found.
}
?>
BrandonO
  • 231
  • 2
  • 10
  • Great, I'm glad that worked! Do you mind clicking the accept check mark to the left of my answer? You can learn more about accepting answers here: https://stackoverflow.com/help/someone-answers – BrandonO Jan 04 '19 at 21:13