Last active
February 13, 2017 05:08
-
-
Save TemaSM/b2670cdc21f2aa338523e053cf6ea72b to your computer and use it in GitHub Desktop.
[PHP] Get file by latest version from current directory (electron-builder / nsis-web)
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
<? | |
// Author: Tema Smirnov [https://github.com/TemaSM] © 2017 | |
$iVersion= 0; | |
$filename = "<filename>.ext"; | |
$regexp = "/([-A-z]+)-([\.0-9]+)-([a-z]+)-([a-z0-9]+).+nsis.7z/"; | |
/* Example: MyProject-0.0.1-alpha-x64.nsis.7z | |
0 => MyProject-0.0.1-alpha-x64.nsis.7z | |
1 => MyProject | |
2 => 0.0.1 | |
3 => alpha | |
4 => x64 | |
*/ | |
foreach (new DirectoryIterator(__DIR__) as $file) { | |
if ($file->isFile()) { | |
preg_match($regexp, $file->getFilename(), $matches); | |
$ver = str_replace('.', '', $matches[2]); | |
if ($ver > $iVersion) { | |
$iVersion= $ver; | |
$filename = $matches[0]; | |
} // print $file->getFilename() . "\n"; | |
} | |
} | |
$URL = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; | |
$fileURL = $URL . $filename; | |
// echo $fileURL; | |
header('Location: '.$fileURL); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment