-=[ Mr. Bumblebee ]=-
_Indonesia_

Path : /var/www/html/inc/class/
File Upload :
Current File : /var/www/html/inc/class/function.file.php

<?php

###########################################
// file/directory
###########################################

	function create_dir ( $path , $mod = '777' )
	{
		$dir = $_SERVER['DOCUMENT_ROOT'] ;
		if ( is_dir ( $dir . '/' . $path))
			$dir = $dir . '/' . $path ;
		else
		{
			if (!empty($dir))
			{
				$dirs = explode('/', $path);
				foreach ($dirs as $key=>$val)
				{
					$dir.= '/' . $val;
					if (!is_dir($dir))
					{
						umask(011);
						mkdir($dir, 0777 );
						chmod($dir, 0777 );
					}
				}
			}
		}
		return $dir;
	}

	function file_delete ( $file_path )
	{
		if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/' . $file_path))
			unlink( $_SERVER['DOCUMENT_ROOT'] . '/' . $file_path ) ;
	}

	function file_effectiveness_check ( $filename ) {
		if ( empty($filename)) return true ;
		$last_ext = substr( $filename  , strrpos($filename , '.' ) + 1);
		$last_ext = strtoupper($last_ext);
		if ( $last_ext == 'PHP' || $last_ext == 'ASP' || $last_ext == 'JSP' || $last_ext == 'HTML' || $last_ext == 'HTM' || $last_ext == 'CGI' )
			return false ;
		else
			return true ;
	}

	function file_effectiveness_name ( $filename ) {
		if ( empty($filename)) return ;
		$filename = str_replace(' ' , '_' , $filename) ;
		$filename = str_replace('#' , '' , $filename) ;
		$filename = str_replace('%' , '' , $filename) ;
		return $filename ;
	}

	function file_upload ( $tmp_file_path , $upload_file_name , $save_file_dir )
	{
		global $info_file ;
		if ( empty($upload_file_name)) return ;
		if ( file_effectiveness_check($upload_file_name) === false ) return ;
		$dir = create_dir ( $save_file_dir ) ;
		$real_file_name = file_effectiveness_name ( $upload_file_name ) ;
		if (( filesize( $tmp_file_path)/1024) > $info_file['max_size'])
		{  // 4000kb
			msg_box (( $info_file['max_size']/1000) . 'MB ÀÌ»óÀÇ ÆÄÀÏÀº À¥»ó¿¡¼­ ¾÷·Îµå ÇÒ ¼ö ¾ø½À´Ï´Ù. ') ;
			return ;
		}
		$chk_file = $dir . '/' . $real_file_name ;
		$tmp_real_file = $real_file_name ;
		$x = 1 ;
		while ( @file_exists($chk_file))
		{
			$tmp_real_file = $x . '_' . $real_file_name ;
			$chk_file = $dir . '/' . $tmp_real_file ;
			$x++;
		}
		@move_uploaded_file ( $tmp_file_path , $chk_file ) ;
		return $tmp_real_file ;
	}

	function file_copy ( $original_path , $original_file , $copy_path )
	{
		if ( empty($original_file)) return ;
		$dir = create_dir ( $copy_path ) ;
		$tmp_real_file = time() . '000' . '.' .substr( $original_file  , strrpos($original_file , '.' ) + 1);
		$chk_file = $dir . '/' . $tmp_real_file ;
		$x = 1 ;
		while (@file_exists($chk_file))
		{
			$tmp_real_file = time() . str_pad( $x , 3 , '0' , STR_PAD_LEFT ) . '.' . substr( $original_file  , strrpos($original_file , '.' ) + 1) ;
			$chk_file = $dir . '/' . $tmp_real_file ;
			$x++;
		}
		$copy_file_state = @copy($_SERVER['DOCUMENT_ROOT'] . '/' . $original_path . '/' . $original_file , $chk_file ) ;
		if ( $copy_file_state ) return $tmp_real_file ;
		else
		{
			msg_box ( ' ÆÄÀÏÀ» º¹»çÇÏÁö ¸øÇß½À´Ï´Ù. ') ;
			return ;
		}
	}

	function file_getimagesize ( $path ) {
		$info = list($width, $height, $type, $attr) = getimagesize($path);
		/* $INFO = array (
				[0]=>161
				[1]=>425
				[2]=>2
				[3]=> width='161' height='425'
				[bits]=>8
				[channels]=>3
				[mime]=>image/jpeg
		); */
		// À̹ÌÁö°¡ ¾Æ´Ò °æ¿ì false °¡ ¹ÝȯµÇ±â ¶§¹®
		if ( $info === false ) return true ;
		// À̹ÌÁöÀ̸é..
		else return $info;
	}

	function file_info ( $path , $server = 'THIS' )
	{
		if ($server != 'THIS')
		{
			if (strpos(strtolower($path),'http://') === false) $path = 'http://' . $path;
			return $path;
		}
		else
		{
			if (substr($path,0,1) != '/') $path = '/' . $path;
			if ( is_file($_SERVER['DOCUMENT_ROOT'] . $path))
			{
				$info = file_getimagesize($_SERVER['DOCUMENT_ROOT'] . $path);
				if ( $info === false ) return true ;
				// À̹ÌÁöÀ̸é..
				else return $info;
			}
			else return false ;
		}
	}

	function file_s_size ( $width , $height , $resize_width , $resize_height ) {
		if ( $width <= $resize_width && $height <= $resize_height)
		{
			$return_value = array (
				'width'				=> $width ,
				'height'			=> $height ,
				'real_width'		=> $width ,
				'real_height'		=> $height
			) ;
		}
		else
		{
			if ( $width > $resize_width && $height < $resize_height )
				$rate = $width/$resize_width ;
			else if ( $width < $resize_width && $height > $resize_height )
				$rate = $height/$resize_height ;
			else
			{
				$r_w = $width/$resize_width ;
				$r_h = $height/$resize_height ;
				if ( $r_w < $r_h ) $rate = $r_h ;
				else $rate = $r_w ;
			}
			$return_value = array (
				'width'			=> intVal($width/$rate) ,
				'height'		=> intVal($height/$rate) ,
				'real_width'	=> $width ,
				'real_height'	=> $height
			) ;
		}
		return $return_value ;
	}

	function file_s_down ( $path , $max_width , $max_height , $server = 'THIS' )
	{
		if ( $server == 'OTHER' ) $path = file_info ( $path , $server ) ;
		else $info = file_info ( $path , $server ) ;
		if ( $info )
		{
			if ( empty($max_width)) $max_width = $info[0] ;
			if ( empty($max_height)) $max_height = $info[1] ;
			$return_value = file_s_size ( $info[0] , $info[1] , $max_width , $max_height ) ;
			return $return_value ;
		}
		else
			return false ;
	}

	function file_separate($keyword, $target_file)
	{
		$keyword = strtoupper($keyword);
		$begin = '<!-- BEGIN OF ' . $keyword . ' -->';
		$end = '<!-- END OF ' . $keyword . ' -->';
		$temp = 0;
		$result = '';
		if (substr($target_file,0,1) == '/')
			$file_path = $_SERVER['DOCUMENT_ROOT'] . $target_file;
		else
			$file_path = $_SERVER['DOCUMENT_ROOT'] . '/' . $target_file;
		if (is_file($file_path))
		{ // ÆÄÀÏÀÌ ÀÖÀ¸¸é
			$fp = fopen($file_path, 'r');
			while (!feof($fp))
			{ // ¹®¼­ÀÇ ³¡ÀÌ¸é ¸ØÃä´Ï´Ù.
				$html = fgets($fp);
				if (strpos(' ' . $html, $begin) > 0)
				{ // ½ÃÀÛ Å°¿öµå¸¦ ã¾ÒÀ¸¸é ±â·Ï ½ÃÀÛ
					$temp = 1;
					continue;
				}
				if (strpos(' ' . $html, $end) > 0) // Á¾·á Ű¿öµå¸¦ ã¾ÒÀ¸¸é ¸ØÃä´Ï´Ù.
					break;
				if ($temp == 1) $result.= $html;
			}
			fclose($fp);
			return $result;
		}
		else
			return ' ERROR - There is no file ';
	}

	function file_ext_tag ( $path , $width , $height )
	{
		$target_ext = strtolower ( substr( $path  , strrpos($path , '.' )+1)  );
		if ( !empty($width)) $width = ' width="' . $width . '" ' ;
		if ( !empty($height)) $height = ' height="' . $height . '" ' ;
		switch ( $target_ext )
		{
			// image
			case 'gif' :
			case 'jpg' :
			case 'jpeg' :
			case 'png' :
			case 'bmp' :
			case 'jpe' :
				$return_value = '<img src="' . $path . '" ' . $width . $height . '  >' ;
				break ;
			// movie
			case 'swf' :
			case 'asf' :
			case 'asx' :
			case 'avi' :
			case 'mov' :
			case 'mpg' :
			case 'mpeg' :
			case 'wma' :
				$return_value = '<embed src="' . $path . '" ' . $width . $height . ' >' ;
				break;
		}

		return $return_value ;
	}



?>

Copyright © 2017 || Recoded By Mr.Bumblebee