-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathbootstrap.php
79 lines (63 loc) · 2.55 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
// =============================================================================
// == Application constants ====================================================
// =============================================================================
// Directories
define('DIR_ROOT', '/local1/work/ginkgo');
define('DIR_UPLOADS', DIR_ROOT . '/uploads');
// URLs
define('URL_ROOT', 'http://qb.cshl.edu/ginkgo');
define('URL_UPLOADS', URL_ROOT . '/uploads');
// Minimum number of cells to perform an analysis
$GINKGO_MIN_NB_CELLS = 3;
// =============================================================================
// == Misc. configuration ======================================================
// =============================================================================
set_time_limit(0);
error_reporting(E_ALL);
session_start();
// =============================================================================
// == Helper functions =========================================================
// =============================================================================
// Generate random ID of arbitrary length
function generateID($length = 20)
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
// Return list of files uploaded by user (excluding . and ..)
function getMyFiles($userID, $ext = 'bed')
{
$directory = DIR_UPLOADS . '/' . $userID . '/';
//$files = array_diff(scandir($directory), array('..', '.'));
$files = array_diff(glob($directory . '/*.' . $ext), array('..', '.'));
$files2= array_diff(glob($directory . '/*.' . $ext . '.gz'), array('..', '.'));
$files = array_merge($files, $files2);
// file_put_contents('wtf', print_r($files, true));
$result = array();
foreach($files as $file)
if(pathinfo($filename, PATHINFO_EXTENSION) != $ext)
$result[] = basename($file);
return $result;
}
//
function sanitize(&$item, $key)
{
$item = escapeshellarg($item);
}
// Modified from http://stackoverflow.com/questions/15188033/human-readable-file-size
function humanFileSize($fileDir, $unit = "")
{
$size = filesize($fileDir);
if( (!$unit && $size >= 1<<30) || $unit == "GB")
return number_format($size/(1<<30), 2) . " GB";
if( (!$unit && $size >= 1<<20) || $unit == "MB")
return number_format($size/(1<<20), 2) . " MB";
if( (!$unit && $size >= 1<<10) || $unit == "KB")
return number_format($size/(1<<10), 0) . " KB";
return number_format($size)." bytes";
}