SfePy: Downloads
It is recommended to download the latest release of SfePy.
';
echo '
| Filename | UploadDate | Size | DownloadCount | |
';
// echo '
| Filename | UploadDate | Size | |
';
$tgz_files = glob($GLOBALS['download_dir'].'/*.{tar.gz}', GLOB_BRACE);
$itgz_files = array_reverse($tgz_files, true);
foreach($itgz_files as $file_) {
$file = basename($file_);
$sql = 'SELECT version,num_downloads FROM sfepy_downloads WHERE version="'.$file.'"';
if (!($data = mysqli_query($con, $sql))) {
die('DB Error, could not query the database: ' . mysqli_error($con));
}
if (mysqli_num_rows($data) == 0) {
$sql = 'INSERT INTO sfepy_downloads values ("'.$file.'", 0)';
mysqli_query($con, $sql);
$version = $file;
$num_downloads = 0;
}
else {
list($version, $num_downloads) = mysqli_fetch_row($data);
}
$size = filesize($file_);
$modtime = date("M d Y", filemtime($file_));
$tag = '
| '.$version.' | '.$modtime.' | '.$size.' bytes | '.$num_downloads.' | |
';
echo $tag;
mysqli_free_result($data);
}
echo '';
mysqli_close($con);
}
function download($version) {
$version_ = $GLOBALS['download_dir'].$version;
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($version_));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($version_));
ob_clean();
flush();
readfile($version_);
$con = mysqli_connect('127.0.0.1:3307', 'sfepy', 'sfepyheslo2018', 'sfepy');
if (mysqli_connect_errno($con)) {
die('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$sql = 'SELECT num_downloads FROM sfepy_downloads WHERE version="'.$version.'"';
if (!($data = mysqli_query($con, $sql))) {
die('DB Error, could not query the database: ' . mysqli_error($con));
}
list($num_downloads) = mysqli_fetch_row($data);
$num_downloads = $num_downloads + 1;
$sql = 'UPDATE sfepy_downloads SET num_downloads="'.$num_downloads.'" WHERE version="'.$version.'"';
if (!mysqli_query($con, $sql)) {
die('DB Error, could not query the database: ' . mysqli_error($con));
}
mysqli_free_result($data);
mysqli_close($con);
}
function dwl($version) {
$tag = $_SERVER['PHP_SELF'].'?fun=download2&ver='.$version;
header('Refresh: 0; '.$tag);
flush();
$tag = 'https://sfepy.org/doc-devel/installation.html';
echo '
Thank you for downloading SfePy! Check out the
installation instructions.';
}
if(!isset($_GET['fun'])){
$fun = 'list';
} else {
$fun = $_GET['fun'];
}
switch($fun) {
case 'list': init(); break;
case 'download2': download($_GET['ver']); break;
case 'download': dwl($_GET['ver']); break;
}
?>