<?php
$filepath = 'test.xls';
$filepath = preg_replace('/^.+[\\\\\\/]/', '', $filepath);

// 파일 경로에 "." 또는 ".."을 이용한 보안취약점 제거
$filesize = filesize($filepath);
$path_parts = pathinfo($filepath);
$filename = $path_parts['basename'];
$extension = $path_parts['extension'];
 
header("Pragma: public");
header("Expires: 0");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $filesize");
 
ob_clean();
flush();
readfile($filepath);
?>
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,
<?php
$ipCheck = false;
$compareIp = array();

$remote = $_SERVER[REMOTE_ADDR];
$remoteIp = explode(".", $remote);

$result = array('1.1.1.*','2.2.2.2');

foreach($result as $key) {
    $ip = explode(".", $key);
    if($key == "*" || $key == $remote) {
        $ipCheck = true;
        break;
	}

	for($i = 0;$i < count($ip);$i++) {
		if($ip[$i] != $remoteIp[$i] && $ip[$i] != "*") {
			continue;
		} else {
			$compareIp[$i] = true;
		}
	}

	if(@$compareIp[0] && @$compareIp[1] && @$compareIp[2] && @$compareIp[3]) {
		$ipCheck = true;
		break;  
	}
}

if($ipCheck != true) {
	echo "접속제한 IP입니다.";
	exit;
}
?>
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,
 // php 버전업으로 인한 globals 함수
 // $_FILES[변수명][tmp_name] => $변수명_name;
 // 기존 $_FILES[변수명][name]은 버리기
 if($_FILES) {
	foreach ($_FILES as $key => $value) { 
		foreach($value as $key2 => $value2) {
			if($key2 == "name") continue;
			if($key2 == "tmp_name") {
				${$key."_name"} = $value2;
			} else {
				${$key."_".$key2} = $value2;
			}
			echo " : ";
			echo $value2;
			echo "<br />";
		}
	}
}

'php, codeigniter' 카테고리의 다른 글

파일 다운로드, 보안 적용  (0) 2015.01.23
아이피[대역폭] 접근제한  (0) 2015.01.20
워터마크(watermark) 찍기  (0) 2015.01.12
png 이미지 글자 쓰기  (0) 2015.01.11
utf-8 글자 자르기  (0) 2015.01.02
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,
<?php
function waterMarkImage($sourceFile, $waterMarkText, $destinationFile) {
	list($width, $height) = getimagesize($sourceFile);
	$image_p = imagecreatetruecolor($width, $height);
	$image = imagecreatefromjpeg($sourceFile);
	imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height);
	$black = imagecolorallocate($image_p, 0, 0, 0);
	$font = 'gulim.ttc';
	$font_size = 10;
	imagettftext($image_p, $font_size, 0, 10, 20, $black, $font, $waterMarkText);
	if($destinationFile <> "") {
		imagejpeg($image_p, $destinationFile, 100);
	} else {
		header('Content-Type: image/jpeg');
		imagejpeg($image_p, null, 100);
	};
	imagedestroy($image);
	imagedestroy($image_p);
}

$sourceFile = './source.jpg';
$destinationFile = './watermark.jpg'; 
$waterMarkText = 'copyright';
waterMarkImage($sourceFile, $waterMarkText, $destinationFile);
?>
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,

* button.php

<?php
header("Content-type: image/png");
$string = $_GET['text'];
$im = imagecreatefrompng("button.png");
$orange = imagecolorallocate($im, 60, 87, 156); // 60,87,156은 RGB값
$px = (imagesx($im) - 7.5 * strlen($string)) / 2; // 7.5는 한글자의 폭
imagestring($im, 4, $px, 9, $string, $orange); // 4는 폰트종류, $px는 x축, 9는 y축
imagepng($im);
imagedestroy($im);
?>

* 이미지 실시간 표시

<html>
<body>
	<img src="button.php?text=intro" />
	<img src="button.php?text=member" />
	<img src="button.php?text=history" />
	<img src="button.php?text=mission" />
</body>
</html>
출처 : https://opentutorials.org/course/62/5137

 

'php, codeigniter' 카테고리의 다른 글

php 버전업으로 인한 기존 globals의 $_FILES  (0) 2015.01.13
워터마크(watermark) 찍기  (0) 2015.01.12
utf-8 글자 자르기  (0) 2015.01.02
코드이그나이터 : IIS에서 index.php 지우기  (0) 2014.12.26
요일 구하기  (0) 2014.12.24
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,
function inc_stringcutU($str, $limit)
	/* Note: */
	/* $str must be a valid UTF-8 string */
	/* it may return an empty string even if $limit > 0 */
{
	$len= strlen($str);

	if ($len<= $limit )
		return $str;

	$len= $limit;

	/* ASCII are encoded in the range 0x00 to 0x7F
	* The first byte of multibyte sequence is in the range 0xC0 to 0xFD.
	* All furthur bytes are in the range 0x80 to 0xBF.
	*/

	while ($len > 0 && ($ch = ord($str[$len])) >= 128 && ($ch < 192))
		$len --;
	
    $word = substr($str, 0, $len).".."; 
	return $word;
}

'php, codeigniter' 카테고리의 다른 글

워터마크(watermark) 찍기  (0) 2015.01.12
png 이미지 글자 쓰기  (0) 2015.01.11
코드이그나이터 : IIS에서 index.php 지우기  (0) 2014.12.26
요일 구하기  (0) 2014.12.24
mysql 인젝션(injection) 방어  (0) 2014.12.10
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,