Пример #1
0
function purgeFiles($temp_dir, $purge_time_limit, $file_type, $debug_ajax = 0)
{
    //$now_time = mktime();
    $now_time = time();
    if (@is_dir($temp_dir)) {
        if ($dp = @opendir($temp_dir)) {
            while (($file_name = readdir($dp)) !== false) {
                if ($file_name !== '.' && $file_name !== '..' && strcmp(getFileExtension($file_name), $file_type) == 0) {
                    if ($file_time = @filectime($temp_dir . $file_name)) {
                        if ($now_time - $file_time > $purge_time_limit) {
                            @unlink($temp_dir . $file_name);
                        }
                    }
                }
            }
            closedir($dp);
        } else {
            if ($debug_ajax) {
                showDebugMessage('Failed to open temp_dir ' . $temp_dir);
            }
            showAlertMessage("<span class='ubrError'>ERROR</span>: Failed to open temp_dir", 1);
        }
    } else {
        if ($debug_ajax) {
            showDebugMessage('Failed to find temp_dir ' . $temp_dir);
        }
        showAlertMessage("<span class='ubrError'>ERROR</span>: Failed to find temp_dir", 1);
    }
}
Пример #2
0
    } elseif ($error_num == 2 || $error_num == 3) {
        $formatted_error_msg = "<span class='ubrError'>ERROR</span>: " . $error_msg;
    }
    showAlertMessage($formatted_error_msg, 1);
} else {
    // Keep trying to read the hook file until timeout
    if ($_INI['cgi_upload_hook']) {
        for ($i = 0; $i < $_INI['hook_timeout_limit']; $i++) {
            if ($hook_data = readUbrFile($hook_file, $_INI['debug_ajax'])) {
                $found_hook_file = true;
                break;
            }
            clearstatcache();
            sleep(1);
        }
    }
    // Failed to find the hook file in the alloted time
    if ($_INI['cgi_upload_hook'] && !$found_hook_file) {
        if ($_INI['debug_ajax']) {
            showDebugMessage("Failed to find hook file {$hook_file}");
        }
        showAlertMessage("<span class='ubrError'>ERROR</span>: Failed to find hook file", 1);
    }
    if ($_INI['debug_ajax']) {
        showDebugMessage("Found flength file {$flength_file}");
        if ($_INI['cgi_upload_hook']) {
            showDebugMessage("Found hook file {$hook_file}");
        }
    }
    startProgressBar($UPLOAD_ID, $total_upload_size, $start_time);
}
Пример #3
0
	clearstatcache();
}

if(!$found_flength_file){
	if($DEBUG_AJAX){ showDebugMessage("Failed to find flength file $flength_file"); }
	showAlertMessage("<font color='red'>ERROR</font>: Failed to find <a href='http://uber-uploader.sourceforge.net/?section=flength' target='_new'>flength file</a>", 1);
}
elseif(strstr($total_upload_size, "ERROR")){
	if($DEBUG_AJAX){ showDebugMessage("Error in flength file $flength_file"); }
	deleteTempUploadDir($TEMP_DIR, $UPLOAD_ID);
	stopUpload();
	showAlertMessage($total_upload_size, 1);
}
else{
	if($DEBUG_AJAX){ showDebugMessage("Found flength file $flength_file"); }
	startProgressBar($UPLOAD_ID, $total_upload_size, $start_time);
}

//////////////////////////////////////////////////////////FUNCTIONS //////////////////////////////////////////////////////////////////

// Remove the temp directory based on upload id
function deleteTempUploadDir($temp_dir, $upload_id){
	$temp_upload_dir = $temp_dir . $upload_id . '.dir';

	if($handle = @opendir($temp_upload_dir)){
		while(false !== ($file_name = readdir($handle))){
			if($file_name != "." && $file_name != ".."){ @unlink($temp_upload_dir . '/' . $file_name); }
		}
		closedir($handle);
	}
Пример #4
0
    if (!createDir($_CONFIG['log_dir'])) {
        if ($_INI['debug_ajax']) {
            showDebugMessage('Failed to create log_dir ' . $_CONFIG['log_dir']);
        }
        showAlertMessage("<span class='ubrError'>ERROR</span>: Failed to create log_dir", 1);
    }
}
// Purge old .link files
if ($_INI['purge_link_files']) {
    purgeFiles($TEMP_DIR, $_INI['purge_link_limit'], 'link', $_INI['debug_ajax']);
}
// Purge old .redirect files
if ($_INI['purge_redirect_files']) {
    purgeFiles($TEMP_DIR, $_INI['purge_redirect_limit'], 'redirect', $_INI['debug_ajax']);
}
// Show debug message
if ($_INI['debug_ajax']) {
    showDebugMessage("Upload ID = {$UPLOAD_ID}");
}
// Write link file
if (writeLinkFile($_CONFIG, $DATA_DELIMITER)) {
    if ($_INI['debug_ajax']) {
        showDebugMessage('Created link file ' . $PATH_TO_LINK_FILE);
    }
    startUpload($UPLOAD_ID, $_INI['debug_upload'], $_INI['debug_ajax']);
} else {
    if ($_INI['debug_ajax']) {
        showDebugMessage('Failed to create link file ' . $PATH_TO_LINK_FILE);
    }
    showAlertMessage("<span class='ubrError'>ERROR</span>: Failed to create link file: {$UPLOAD_ID}.link", 1);
}
Пример #5
0
if($PURGE_LINK_FILES){ purge_ubr_files($TEMP_DIR, $PURGE_LINK_LIMIT, '.link'); }

// Purge old redirect files
if($PURGE_REDIRECT_FILES){ purge_ubr_files($TEMP_DIR, $PURGE_REDIRECT_LIMIT, '.redirect'); }

// Generate upload id
$UPLOAD_ID = generateUploadID();

// Show debug message
if($DEBUG_AJAX){ showDebugMessage("Upload ID = $UPLOAD_ID"); }

// Write link file
if(write_link_file($TEMP_DIR, $UPLOAD_ID, $DEBUG_UPLOAD, $DELETE_LINK_FILE, $PURGE_TEMP_DIRS, $PURGE_TEMP_DIRS_LIMIT, $_CONFIG)){
	if($DEBUG_AJAX){
		$path_to_link_file = $TEMP_DIR . $UPLOAD_ID . ".link";
		showDebugMessage("Created link file $path_to_link_file");
	}
	startUpload($UPLOAD_ID, $DEBUG_UPLOAD);
}
else{ showAlertMessage("<font color='red'>ERROR</font>: Failed to open link file: $UPLOAD_ID.link", 1); }

//////////////////////////////////////////////////////////FUNCTIONS //////////////////////////////////////////////////////////////////

// Create a directory
function create_dir($dir){
	if(is_dir($dir)){ return true; }
	else{
		umask(0);
		if(@mkdir($dir, 0777)){ return true; }
		else{ return false; }
	}
Пример #6
0
                if ($file_name !== '.' && $file_name !== '..' && $file_name !== $flength_file) {
                    $total_bytes_read += sprintf("%u", @filesize($temp_upload_dir . '/' . $file_name));
                    $files_uploaded++;
                }
            }
            @closedir($handle);
            if ($files_uploaded > 0) {
                $files_uploaded -= 1;
            }
        } else {
            $upload_active = 0;
        }
    }
}
if ($upload_active && $total_bytes_read < $_GET['total_upload_size']) {
    $lapsed_time = time() - $_GET['start_time'];
    if ($_INI['debug_ajax']) {
        if ($_INI['cgi_upload_hook']) {
            showDebugMessage("Set progress: bytes uploaded=" . $total_bytes_read . " files uploaded=" . $files_uploaded . " current file=" . $current_filename . " bytes read=" . $bytes_read . " lapsed time=" . $lapsed_time);
        } else {
            showDebugMessage("Set progress: bytes uploaded=" . $total_bytes_read . " files uploaded=" . $files_uploaded . " lapsed time=" . $lapsed_time);
        }
    }
    setProgressStatus($total_bytes_read, $files_uploaded, $current_filename, $bytes_read, $lapsed_time);
    getProgressStatus($_INI['get_progress_speed']);
} else {
    stopDataLoop();
    if ($_INI['debug_ajax']) {
        showDebugMessage("<span class='ubrWarning'>WARNING</span>: No active upload detected {$path_to_flength_file}");
    }
}
Пример #7
0
	if($DEBUG_AJAX){ showDebugMessage("Set progress: bytes uploaded=" . $read_status->bytes_uploaded . " lapsed time=" . $lapsed_time . " uploaded files=" . $read_status->uploaded_files); }

	setProgressStatus($read_status->bytes_uploaded, $lapsed_time, $read_status->uploaded_files);
	getProgressStatus($GET_PROGRESS_SPEED);
}
else{
	stopDataLoop();
	hideProgressBar();

	if($DEBUG_AJAX){
		if(!$read_status->active && $read_status->is_dir_error && !$embedded_upload_results){
			showDebugMessage("<font color='green'>WARNING</font>: Cannot find upload temp directory<br>");
		}
		elseif(!$read_status->active && $read_status->open_dir_error && !$embedded_upload_results){
			showDebugMessage("<font color='green'>WARNING</font>: Cannot open upload temp directory<br>");
		}
	}
}

//////////////////////////////////////////////////////////FUNCTIONS //////////////////////////////////////////////////////////////////

//Class to store read info
class ReadStatus{
	var $is_dir_error = 0;
	var $open_dir_error = 0;
	var $active = 0;
	var $uploaded_files = 0;
	var $bytes_uploaded = 0;
}