forked from MightyGorgon/icy_phoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalbum_nuffload_pbar.php
More file actions
183 lines (166 loc) · 4.26 KB
/
album_nuffload_pbar.php
File metadata and controls
183 lines (166 loc) · 4.26 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/**
*
* @package Icy Phoenix
* @version $Id$
* @copyright (c) 2008 Icy Phoenix
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
*
* @Extra credits for this file
* Nuffmon (nuffmon@hotmail.com)
*
*/
define('IN_ICYPHOENIX', true);
if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
include(IP_ROOT_PATH . 'common.' . PHP_EXT);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
// End session management
// Get general album information
include(ALBUM_MOD_PATH . 'album_common.' . PHP_EXT);
function hms($sec)
{
$thetime = str_pad(intval(intval($sec) / 3600), 2, "0", STR_PAD_LEFT) . ":" . str_pad(intval(($sec / 60) % 60), 2, "0", STR_PAD_LEFT) . ":" . str_pad(intval($sec % 60), 2, "0", STR_PAD_LEFT) ;
return $thetime;
}
// Check session_id and monitor upload or quit
if(isset($_REQUEST['sessionid']))
{
// Set unlimited timeout
set_time_limit(0);
$start_time = time(); //Set start time as now
$sessionid = $_REQUEST['sessionid'];
// Path to data files
$info_file = $album_config['path_to_bin'] . "tmp/$sessionid"."_flength";
$data_file = $album_config['path_to_bin'] . "tmp/$sessionid"."_postdata";
//$signal_file = $album_config['path_to_bin'] . "tmp/$sessionid"."_signal";
// Dump page header
$gen_simple_header = true;
$meta_content['page_title'] = $lang['upload_in_progress'];
$meta_content['description'] = '';
$meta_content['keywords'] = '';
if(!$album_config['simple_format'])
{
page_header();
}
// Load template
$template->set_filenames(array('body' => 'album_nuffload_pbar_body.tpl'));
// Load template variable
$template->assign_vars(array(
'L_ALBUM' => $lang['album'],
'L_UPLOAD_PIC' => $lang['Upload_Pic'],
'L_UPLOAD_IN_PROGRESS' => $lang['upload_in_progress'],
'L_TIME_ELAPSED' => $lang['time_elapsed'],
'L_TIME_REMAINING' => $lang['time_remaining'],
'L_NUFFLOAD_VERSION' => 'v1.4.2'
)
);
page_footer(false);
$db->sql_close();
// Loop/monitor filesize until complete
$upload_started = false;
for(;$percent_done < 100;)
{
// Open info file to find filesize
// info file created by perl script
if (intval($total_size) <= 0)
{
if ($fp = @fopen($info_file, 'r'))
{
$fd = @fread($fp, 1000);
@fclose($fp);
$total_size = $fd;
}
}
$time_elapsed = time()- $start_time;
$previous_size = $current_size;
@clearstatcache();
if (@file_exists($data_file))
{
$current_size = @filesize($data_file);
$upload_started = true;
}
else
{
if ($upload_started)
{
?>
<script type="text/javascript">
<!--
top.close();
// -->
</script>
<?php
exit;
}
}
// This section checks for no activity and stops processing
if ($previous_size < $current_size)
{
$activity_time = 0;
}
else
{
$activity_time++;
}
if ($activity_time >= $album_config['max_pause'])
{
?>
<script type="text/javascript">
<!--
top.close();
// -->
</script>
<?php
exit;
}
// Calculate progress values if upload started.
if ($current_size > 0 && $time_elapsed > 0)
{
$percent_done = sprintf("%.0f",($current_size / $total_size) * 100);
$speed = ($current_size / $time_elapsed);
if ($speed == 0) {$speed = 1024;}
$time_remain_str = hms(($total_size-$current_size) / $speed);
$time_elapsed_str = hms($time_elapsed);
}
if ($percent_done < 1)
{
$percent_done = 1;
}
?>
<script type="text/javascript">
<!--
document.getElementById("progress1").width = "<?php print $percent_done; ?>%";
document.getElementById("progress2").innerHTML = '<? echo $current_size; ?>/<? echo $total_size; ?> (<? echo $percent_done; ?>%) <? echo printf("%.2f",$speed/1024); ?> kbit/s<br /><? echo $lang['time_elapsed'] . ": " . $time_elapsed_str; ?><br /><? echo $lang['time_remaining'] . ": " . $time_remain_str; ?>';
// -->
</script>
<?php
ob_flush();
flush();
sleep(1);
}
// Now we have finished we can delete the data files
/*
@unlink($info_file);
@unlink($data_file);
@unlink($signal_file);
*/
// Send javascript to close form if required
if ($album_config['close_on_finish'])
{
?>
<script type="text/javascript">
<!--
top.close();
// -->
</script>
<?php
}
}
?>