ERROR: Failed to open $paramFileName"); }
while(!feof($fh)){
$buffer = fgets($fh, 4096);
@list($key, $value) = explode('=', trim($buffer));
$value = str_replace("~EQLS~", "=", $value);
$value = str_replace("~NWLN~", "\r\n", $value);
if(isset($key) && isset($value) && strlen($key) > 0 && strlen($value) > 0){
if(preg_match('/(.*)\[(.*)\]/i', $key, $match)){ $param_array[$match[1]][$match[2]] = $value; }
else{ $param_array[$key] = $value; }
}
}
fclose($fh);
if(isset($param_array['delete_param_file']) && $param_array['delete_param_file'] == 1){
for($i = 0; $i < 5; $i++){
if(@unlink($paramFileName)){ break; }
else{ sleep(1); }
}
}
return $param_array;
}
function index() {
// Provide upload interface
if ( $this->Session->read('User') ) {
header('Content-type: text/html; charset=UTF-8');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.date('r'));
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
$tmp_sid = md5(uniqid(mt_rand(), true));
$this->path_to_upload_script .= '?tmp_sid=' . $tmp_sid;
$this->path_to_ini_status_script .= '?tmp_sid=' . $tmp_sid;
if ( $this->default_config_file != 'uu_default_config' ) {
$this->path_to_upload_script .= '&config_file='.$this->default_config_file;
$this->path_to_ini_status_script .= '&config_file='.$this->default_config_file;
}
$this->set('path_to_upload_script', $this->path_to_upload_script);
$this->set('path_to_ini_status_script', $this->path_to_ini_status_script);
$this->set('check_file_name_format', $this->check_file_name_format);
$this->set('check_disallow_extensions', $this->check_disallow_extensions);
$this->set('check_allow_extensions', $this->check_allow_extensions);
$this->set('check_null_file_count', $this->check_null_file_count);
$this->set('check_duplicate_file_count', $this->check_duplicate_file_count);
$this->set('max_upload_slots', $this->max_upload_slots);
$this->set('cedric_progress_bar', $this->cedric_progress_bar);
$this->set('progress_bar_width', $this->progress_bar_width);
}
}
function finished() {
if ( !isset($_REQUEST['tmp_sid']) || strlen($_REQUEST['tmp_sid']) != 32 ) {
echo("WARNING: Invalid session-id.
\n");
} else {
$temp_dir = $_REQUEST['temp_dir'];
$_POST_DATA = $this->getPostData($temp_dir, $_REQUEST['tmp_sid']);
// Move the file to an filedb and enter it into the database.
foreach ( $_POST_DATA as $post_key => $post_value ) {
if ( $post_key == 'upfile_0' ) {
$filename = $post_value;
$filepath = $_POST_DATA['upload_dir'].$filename;
if ( is_file($filepath) ) {
$filesize = @filesize($filepath);
/*
if ( $this->othAuth->getData() ) {
$details['user_id'] = $this->othAuth->user('id');
$details['username'] = $this->othAuth->user('username');
} else {
// User is not logged in. What to do here?
}
*/
if ( $userinfo = $this->Session->read('user') ) {
$details['user_id'] = $userinfo['id'];
$details['username'] = $userinfo['username'];
} else {
// Now what?
}
$details['filename_real'] = $filename;
$details['filename_safe'] = preg_replace('`([^a-zA-Z0-9._]+)`is', '_', $filename);
$details['timestamp'] = time();
$details['filesize'] = (int)$filesize;
$details['storage_id'] = 1;
$details['downloaded'] = 0;
#$details['show'] = $_POST_DATA['show'];
$details['show'] = 1;
$details['ipaddress'] = (int)ip2long($_SERVER['REMOTE_ADDR']);
$details['killcode'] = $this->randomKeys(32);
$details['md5'] = md5_file($filepath);
if ( $details['filename_safe']!= $filename ) {
// Filename has changed, turn UTF8 support on.
$query = 'SET NAMES utf8';
$this->Upload->query($query);
}
// Move the file after MySQL made a new entry in the table.
if ( $this->Upload->save($details) ) {
$id = $this->Upload->getLastInsertId();
$details['id'] = $id;
if ( mkdir('/usr/storage/TrackMasters/'.$id) ) {
if ( rename($filepath, '/usr/storage/TrackMasters/'.$id.'/'.$details['filename_safe']) ) {
$this->set('fileDetails', $details);
} else {
$this->set('Error', 'Could not move file to correct path.');
}
} else {
$this->set('Error', 'Could not make directory.');
}
}
}
}
}
}
}
}
?>