Last active
March 27, 2024 08:33
-
-
Save tranchausky/8f1f51ec8a2da1071dc84cf7a3d2b596 to your computer and use it in GitHub Desktop.
php return last version
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 | |
$folderVersion = 'versions'; | |
$version = retunVersion($folderVersion); | |
$file_BIN = 'file.BIN'; | |
$link = 'http://localhost:801/test/upgrade/versions/'; | |
echo viewFileBin($link,$version, $file_BIN); | |
function viewFileBin($link,$version, $file_BIN){ | |
if(empty($version)){ | |
return "no_new"; | |
} | |
return $link.$version.'/'.$file_BIN; | |
} | |
function retunVersion($folderVersion){ | |
$lastVerion = getLastversion($folderVersion); | |
if(isset($_GET['v'])){ | |
if($_GET['v'] == $lastVerion){ | |
return ''; | |
} | |
} | |
return $lastVerion; | |
} | |
function getLastversion($folderVersion){ | |
$images = array_diff(scandir($folderVersion), array('..', '.')); | |
natsort($images); //sort 1,2,3 | |
$images = array_values($images); //reindex | |
//var_dump($images); | |
$count = count($images)-1; | |
$lastVersion = $images[$count]; | |
return $lastVersion; | |
} | |
//http://localhost:801/test/upgrade/ | |
//return | |
//http://localhost:801/test/upgrade/versions/10/file.BIN | |
//http://localhost:801/test/upgrade/?v=10 | |
//return | |
//"no_new" | |
//http://localhost:801/test/upgrade/?v=6 | |
//return | |
//http://localhost:801/test/upgrade/versions/10/file.BIN |
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
versions | |
├───1 | |
│ file.BIN | |
│ | |
├───10 | |
│ file.BIN | |
│ | |
├───2 | |
│ file.BIN | |
│ | |
├───3.4 | |
│ file.BIN | |
│ | |
├───4.4 | |
│ file.BIN | |
│ | |
├───5.6 | |
│ file.BIN | |
│ | |
└───7 | |
file.BIN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment