Example #1
0
	function d3download_download( $url, $filename='', $ext='', $novisit=0 )
	{

		if ( ! preg_match("`^(https?|ftp)://`i", $url ) ) {
			include_once dirname( dirname(__FILE__) ).'/class/upload_validate.php' ;

			if ( ! ini_get( 'safe_mode' ) ) { @set_time_limit(0); }
			if( empty( $filename ) ){
				$f_info   = pathinfo( $url );
				$filename = ( ! empty( $f_info['basename'] ) ) ? $f_info['basename'] : '' ;
				$ext      = ( ! empty( $f_info['extension'] ) ) ? strtolower( $f_info['extension'] ) : '' ;
			}
			$upload_validate = new Upload_Validate ;
			$mtype_arr = $upload_validate->return_mtype();
			$mtype = $mtype_arr[$ext];
			$size= @filesize( $url );
			if( headers_sent() ) die( 'headers are already sent' ) ;
			if ( ! empty( $mtype ) ) {
				header('Content-Type: '.$mtype.'');
			} else {
				header('Content-Type: application/force-download');
			}

			$ua_type = d3download_get_ua_type();
			$current_name = d3download_get_download_name( $filename, $ua_type );

			header('Content-Disposition: attachment; filename="'.$current_name.'"');
			header('Content-Description: File Transfer');
			header('Content-Length: '.$size.'' );
			if ( $ua_type == 'IE' ) {
    			header('Pragma: public');
				header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
			} else {
    			header('Pragma: no-cache');
			}
			if( isset( $mtype ) && strstr( $mtype, 'text/' ) ){
				$fp = fopen( $url, 'r' );
			} else {
				$fp = fopen( $url, 'rb' );
			}
			if ( $size > 1024*1024*2 ) {
				while ( ob_get_level() > 0 ) { ob_end_flush(); }
				while( ! feof( $fp ) ) { print fgets( $fp ); }
				fclose( $fp );
			} else {
				fpassthru( $fp );
			}
			exit();
		} else {
			if ( ! preg_match( "/^ed2k*:\/\//i", $url ) ) { Header("Location: $url"); }
			echo "<html><head><meta http-equiv=\"Refresh\" content=\"0; URL=".$url."\"></meta></head><body></body></html>";
			exit();
		}
	}
Example #2
0
	function d3download_upload_execution( $mydirname, $file_name, $file_tmp_name, $file_error, $maxsize, $id, $uid, $second=0 )
	{
		include_once dirname( dirname(__FILE__) ).'/class/upload_validate.php' ;
		$upload_validate = new Upload_Validate( $mydirname ) ;

		$uploads_dir = XOOPS_TRUST_PATH.'/uploads/'.$mydirname.'/';

		// PHP 4.3.6 以前のバージョンへの対策( .. と / が含まれている場合強制終了 )
		$upload_validate->check_doubledot( $file_name ) ;

		// アップロードされたファイルは、拡張子はなく、ファイル名を変えて保存する
		$site_salt = substr( md5( XOOPS_URL ) , -4 ) ;
		$uploads_filename = $id.'_'.$site_salt.'_'.$uid.'_'.time() ;
		if ( ! empty( $second ) ) $uploads_filename .= '_1' ;
		$uploads_path = $uploads_dir.$uploads_filename ;
		$uploads_url = 'XOOPS_TRUST_PATH/uploads/'.$mydirname.'/'.$uploads_filename ;

		// エラーチェック
		if ( $file_error > 0 ){
			return array(
				'file_name'  => $file_name,
				'error'  => d3download_file_error_message( $file_error ) ,
			) ;
			exit();
		}

		if( is_uploaded_file( $file_tmp_name ) ){
			$f_info = pathinfo( $file_name );
			$f_ext  = ( ! empty( $f_info['extension'] ) ) ? strtolower( $f_info['extension'] ) : '' ;
			$f_size = intval( filesize( $file_tmp_name ) ) ;
			if( $f_size > $maxsize ) {
				return array(
					'file_name'  => $file_name,
					'error'  => _MD_D3DOWNLOADS_FILELARGE ,
				) ;
				exit();
			}

			// 拡張子チェック
			if( ! $upload_validate->check_allowed_extensions( $f_ext ) ){
				redirect_header( XOOPS_URL."/modules/$mydirname/", 2, sprintf( _MD_D3DOWNLOADS_UPLOADERROR_EXT , $f_ext ) ) ;
				exit() ;
			} else {
				// php など危険な拡張子のファイルのアップロードを防ぐ
				$upload_validate->check_deny_extensions( $f_ext ) ;

				// multiple dot file のチェックを行うかどうか
				$check_multiple_dot = $upload_validate->config_check_multiple_dot() ;
				// multiple dot file のチェック
				if( ! empty( $check_multiple_dot ) ){
					$upload_validate->check_multiple_dot( $file_name ) ;
				}

				// 画像ファイルを対象に拡張子偽造のチェック
				$upload_validate->check_image_extensions( $f_ext, $file_tmp_name, $file_name ) ;

				// ヘッダのチェックを行うかどうか
				$check_of_head = $upload_validate->config_validate_of_head() ;
				// ファイルの先頭部を確認して拡張子偽造のチェック
				if( ! empty( $check_of_head ) ){
					$upload_validate->Validate_of_head( $file_tmp_name, $file_name, $f_ext ) ;
				}

				$urs = @move_uploaded_file( $file_tmp_name , $uploads_path ) ;
				if ( $urs === TRUE ) {
					return array(
						'url'  => $uploads_url ,
						'file_name'  => $file_name,
						'ext'  => $f_ext ,
						'size' => $f_size ,
						'error' => '' ,
					) ;
				} else {
					redirect_header( XOOPS_URL."/modules/$mydirname/", 2, _MD_D3DOWNLOADS_UPLOADERROR ) ;
					exit();
				}
			}
		} else {
			redirect_header( XOOPS_URL."/modules/$mydirname/", 2, _MD_D3DOWNLOADS_UPLOADERROR ) ;
			exit();
		}
	}
		'display'=>'',
		'rules'=>array(
			array(
				'method'=>'Validate.Presence',
				'args'=>array(
					'type'=> 'description',
					'failureMessage' => _MD_D3DOWNLOADS_DESCRIPTION_NONE
				)
			),
		)	
	),
);

// set extension data
include_once dirname( dirname(__FILE__) ).'/class/upload_validate.php' ;
$upload_validate = new Upload_Validate() ;
$allowed_extension = '\.'.implode( '|\.',array_diff( $upload_validate->allowed_extension( $mydirname ), $upload_validate->deny_extension() ) );

// 一般設定で設定されている拡張子をチェック
$formRules['fileupload'] = array(
	// File_upload check
	'file_upload_1' => array(
		'args'=>array(
			'validMessage' => _MD_D3DOWNLOADS_URL_OK
		),
		'display'=>'',
		'rules'=>array(
			array(
				'method'=>'Validate.Format',
				'args'=>array(
					'pattern' => '/('.$allowed_extension.')$/i',