2015년 1월 30일 금요일

PHP 디렉토리 함수 정리


/*
opendir, closedir
resource = opendir(string_path)
void closedir(resource_dir_handle)
http://php.net/manual/en/function.opendir.php
http://php.net/manual/en/function.closedir.php
*/
$dir = "../public_html/";
// 알고 있는 디렉토리를 열어서, 내용을 읽어들이는 작업입니다.
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            echo "filename: $file : filetype: " . filetype($dir.$file);
        }
        closedir($dh);
    }
}

/*
readdir
string = readdir(resource_dir_hendle)
http://php.net/manual/en/function.readdir.php
*/
if ($handle = opendir('test/')) {
    echo "Directory handle : " . $handle;
    echo "Files : ";

    /* 디렉토리 안을 루프하는 올바른 방법입니다. */
    while (false !== ($file = readdir($handle))) {
        echo $file;
    }

    /* 디렉토리 안을 루프하는 *잘못된* 방법입니다. */
    while ($file = readdir($handle)) {
        echo $file;
    }

    closedir($handle); 
}

/*
rewinddir
void = rewinddir(resource_dir_handle)
http://php.net/manual/en/function.rewinddir.php
*/
if ($handle = opendir("test")) {
 // 1st
 $filename = readdir($handle);
 echo " file name : " . $filename . "
"; // 2nd $filename = readdir($handle); echo " file name : " . $filename . "
"; // 3rd $filename = readdir($handle); echo " file name : " . $filename . "
"; // 4th $filename = readdir($handle); echo " file name : " . $filename . "
"; // 5th $filename = readdir($handle); echo " file name : " . $filename . "
"; // rewind dir rewinddir($handle); // go to 1st $filename = readdir($handle); echo " file name : " . $filename . "
"; // close dir closedir($handle); } /* chdir bool = chdir(string_directory) http://php.net/manual/en/function.chdir.php */ // 현재 디렉토리 echo getcwd(); // 바뀐 디렉토리 chdir('/public_html/test/'); echo getcwd(); /* dir Class dir(string directory) http://php.net/manual/en/function.dir.php */ $d = dir("css"); echo "Handle: " . $d->handle . "
"; echo "Path: " . $d->path . "
"; while (false !== ($entry = $d->read())) { echo $entry."
"; } $d->close(); /* scandir array = scandir(string_directory, int_sorting_order) http://php.net/manual/en/function.scandir.php */ $dir = 'css'; $files1 = scandir($dir); //asc $files2 = scandir($dir, 1); // desc print_r($files1); print_r($files2);

PHP 파일 시스템 함수 정리


// http://www.gnu.org/licenses/gpl-3.0.txt
$filename = "test.txt";

/*
fopen
resource_handle = fopen(string_filename, string_mode)
http://php.net/manual/en/function.fopen.php
- mode
r  : read, pointer Begin
r+ : read, write, pointer Begin
w  : write, erase, create new file, pointer End 
w+ : write, read, pointer End
a  : add, write, create new file, pointer End
a+ : add, write, read, pointer End
x  : creat new file, write, pointer Begin
x+ : read, write, pointer Begin
c  : write, pointer Begin
c+ : read, write, pointer Begin
*/
$handle = fopen($filename,"r"); // chmod 777 test, "D:\\test\\test.txt"
if ($handle)
{
 echo "file Opened.";
}
else
{
 die("open Failed.");
}

/*
fread
string = fread(resource_handle, int_length)
http://php.net/manual/en/function.fread.php
*/
$handle = fopen($filename,"r");
$temp = fread($handle, 100);
echo $temp;

/*
fwrite, fputs
int = fwrite(resource_handle, string, int)
int = fputs(resource_handle, string, int)
http://php.net/manual/en/function.fwrite.php
http://php.net/manual/en/function.fputs.php
*/
$handle = fopen($filename,"w");
$temp = fwrite($handle, "ABCDEFGabcあいうえお가나다라마바사");
echo $temp;
$temp = fputs($handle, "abcdefg", 3);
echo $temp;
/*
fwrite, fputs
int = fwrite(resource_handle, string, int)
int = fputs(resource_handle, string, int)
http://php.net/manual/en/function.fwrite.php
http://php.net/manual/en/function.fputs.php
*/
$handle = fopen($filename,"w");
$temp = fwrite($handle, "ABCDEFGabcあいうえお가나다라마바사");
echo $temp;
$temp = fputs($handle, "abcdefg", 3);
echo $temp;

/*
feof
bool = feof(resource_handle, int_length)
http://php.net/manual/en/function.feof.php
*/
$temp = "";
$handle = fopen($filename,"r");
while (!feof($handle))
{
 $temp .= fread($handle, 128);
}

/*
fgets
string = fgets(resource_handle, int_length)
http://php.net/manual/en/function.fgets.php
*/
while (($buffer = fgets($handle, 4096)) !== false) {
 echo $buffer;
}
if (!feof($handle)) {
 echo "Error: unexpected fgets() fail\n";
}

/*
fpassthru
int = fpassthru(resource_handle)
http://php.net/manual/en/function.fpassthru.php
*/
if (!feof($handle)) {
 header("Content-Type: text/html");
 header("Content-Length: " . filesize($file));
 fpassthru($handle);
 exit;
}

/*
readfile
int = readfile(string_filename)
http://php.net/manual/en/function.readfile.php
*/
if (file_exists($filename)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($filename));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($filename));
    readfile($filename);
    exit;
}

/*
fgetc
string = fgetc(resource_handle)
http://php.net/manual/en/function.fgetc.php
*/
while (!feof($handle)) {
 $char = fgetc($handle);
 echo $char . ", ";
}

/*
fgetss
string = fgetss(resource_handle)
http://php.net/manual/en/function.fgetss.php
*/
while (!feof($handle)) {
 $strip_tags = fgetss($handle);
 echo $strip_tags;
}

/*
fgetcsv
array = fgetcsv(resource_handle)
http://php.net/manual/en/function.fgetcsv.php
*/
$handle = fopen("test.csv","r");
if ($handle)
{
 while($col = fgetcsv($handle,1024,","))
 {
  $row = count($col);
  //print_r($col);
  foreach ($col as $key=>$val) {
   echo $col[$key] . ",";
  }
  echo "
"; } echo "Total = " . $row; } else { die("open Failed."); } /* file array = file(string_filename) http://php.net/manual/kr/function.file.php */ $array = file("test.txt"); for ($i = 0; $i < count($array); $i++) { echo $array[$i]; } $lines = file("http://php.net/"); while (list($line_num,$line)=each($lines)) { echo "Line" . $line_num . " : " . htmlspecialchars($line) . "
"; } /* filesize int = filesize(string_filename) http://php.net/manual/kr/function.filesize.php */ $size = filesize("test.txt"); echo $size . " Bytes"; /* file_exists bool = file_exists(string_filename) http://php.net/manual/kr/function.file-exists.php */ if (file_exists($filename)) { echo "The file $filename exists"; } else { echo "The file $filename does not exist"; } /* is_executable bool = is_executable(string_filename) http://php.net/manual/kr/function.is-executable.php */ if (is_executable($filename)) { echo $filename.' is executable'; } else { echo $filename.' is not executable'; } /* is_writable bool = is_writable(string_filename) http://php.net/manual/kr/function.is-writable.php */ if (is_writable($filename)) { echo $filename.' is writable'; } else { echo $filename.' is not writable'; } /* copy bool = copy(string_source, string_dest) http://php.net/manual/kr/function.copy.php */ $file = "test.txt"; $newfile = "test.bak"; if (!copy($file, $newfile)){ echo "failed to copy $file...\n"; } /* rename bool = rename(string_oldname, string_newname) http://php.net/manual/kr/function.rename.php */ rename("test.txt", "test.new.txt"); /* unlink bool = unlink(string_filename) http://php.net/manual/kr/function.unlink.php */ unlink("test.csv"); /* mkdir bool = mkdir(string_pathname, int_mode) http://php.net/manual/kr/function.mkdir.php */ $structure = "depth1/depth2/depth3/"; if (!mkdir($structure, 0777, true)) { die("Failed to create folders..."); } /* rmdir bool = rmdir(string_dirname) http://php.net/manual/kr/function.rmdir.php */ if (!is_dir("FolderName")) { mkdir("FolderName"); } rmdir("FolderName"); /* basename string = basename(string_path, string_suffix) http://php.net/manual/kr/function.basename.php */ echo "1) ".basename("/etc/sudoers.txt", ".txt").PHP_EOL; echo "2) ".basename("/etc/passwd").PHP_EOL; echo "3) ".basename("/etc/").PHP_EOL; echo "4) ".basename(".").PHP_EOL; echo "5) ".basename("/"); /* dirname string = dirname(string_path) http://php.net/manual/kr/function.dirname.php */ echo "1) " . dirname("/etc/passwd/test.txt") . PHP_EOL; // 1) /etc/passwd echo "2) " . dirname("/etc/passwd") . PHP_EOL; // 1) /etc echo "3) " . dirname("/etc/") . PHP_EOL; // 2) / (or \ on Windows) echo "4) " . dirname("."); // 3) . /* pathinfo array = pathinfo(string_path) http://php.net/manual/kr/function.pathinfo.php */ $path_parts = pathinfo('/www/htdocs/inc/lib.inc.php'); echo $path_parts['dirname'], "
"; // folder name echo $path_parts['basename'], "
"; // file + extension name echo $path_parts['extension'], "
"; // extension name echo $path_parts['filename'], "
"; // file name /* rewind bool = rewind(resource_handle) http://php.net/manual/kr/function.rewind.php */ $handle = fopen('test.txt', 'r+'); fwrite($handle, 'Really long sentence.'); rewind($handle); fwrite($handle, 'Foo'); rewind($handle); echo fread($handle, filesize('test.txt')); rewind($handle); echo fgets($handle); /* fseek int = fseek(resource_handle, int_offset) http://php.net/manual/kr/function.fseek.php */ $handle = fopen('test.txt', 'r'); while (!feof($handle)) { echo fgets($handle, 4096); } rewind($handle); echo fgets($handle); // move next 10 byte fseek($handle, 10, SEEK_SET); echo fgets($handle); // from now point. move next 5 byte fseek($handle, 5, SEEK_CUR); echo fgets($handle); // from end point. move prev 10 byte fseek($handle, -10, SEEK_END); echo fgets($handle); /* ftell int = ftell(resource_handle) http://php.net/manual/kr/function.ftell.php */ $handle = fopen($filename, "r"); echo ftell($handle); // 0 echo fgets($handle,7); echo ftell($handle); // 6 /* parse_ini_file array = parse_ini_file(string_filename) http://php.net/manual/kr/function.parse-ini-file.php */ define('BIRD', 'Dodo bird'); // Parse without sections $ini_array = parse_ini_file("test.ini"); print_r($ini_array); // Parse with sections $ini_array = parse_ini_file("test.ini", true); print_r($ini_array); /* is_uploaded_file bool = is_uploaded_file(string_filename) http://php.net/manual/kr/function.is-uploaded-file.php */
if (is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) { echo "File ". $_FILES['uploadedfile']['name'] ." uploaded successfully.\n"; echo "Displaying contents\n"; readfile($_FILES['uploadedfile']['tmp_name']); } else { echo "Possible file upload attack: "; echo "filename '". $_FILES['uploadedfile']['tmp_name'] . "'."; } /* move_uploaded_file bool = move_uploaded_file(string_filename, string_destination) http://php.net/manual/kr/function.move-uploaded-file.php */ $uploads_dir = 'iglu'; if (is_uploaded_file($_FILES["uploadedfile"]["tmp_name"])) { //print_r($_FILES); echo "file name : " . $_FILES["uploadedfile"]["name"]; echo "file size : " . $_FILES["uploadedfile"]["size"]; echo "file type : " . $_FILES["uploadedfile"]["type"]; echo "temp name : " . $_FILES["uploadedfile"]["tmp_name"]; //save path $dest = $uploads_dir . "/" . $_FILES["uploadedfile"]["name"]; //save file if (move_uploaded_file($_FILES["uploadedfile"]["tmp_name"], $dest)) { echo "MOVED SUCCESS!"; } else { die("MOVED Failed!"); } } else { die("NO FILE"); } /* fclose bool = fclose(resource_handle) http://php.net/manual/en/function.fopen.php */ $tf = fclose($handle); if($tf) { echo "
file Closed."; } else { echo "
close Failed."; }

2015년 1월 28일 수요일

마이티 나이트(Mighty Knight) 간략 리뷰

킹덤러쉬 오리진 플래쉬를 기다렸지만,
결국 PC 버전은 나오지 않는다는 공식 사이트 포럼의 소식입니다.
( 돈되는 모바일 앱만 출시하겠단말... ㅡㅡ; )

한동안 신작 플래쉬 게임이 뜸했고

재밌는 플래쉬 게임을 찾다가, 우연히 횡스크롤 액션 게임을 발견했습니다.

게임 제목은 "마이티 나이트" 나이츠?

첫 인트로 화면은 '킹덤러쉬'와 비슷.


지도 맵 나오는 것도 '킹덤러쉬' 와 그림체가 비슷.
게임모드도 '킹덤러쉬'와 마찬가지로 3가지.
DEATH 모드는 안해봤는데, 어렵겠지? 아마도


맵을 하나 깰때마다 금화를 준다. 
금화로 무기를 업그레이드 할 수 있다.


이렇게 용병도 살수있다.


횡스크롤 액션게임.

그 옛날 오락실 게임이던, 삼국지 천지를먹다? 같은거.


하지만 이 게임은 유럽스타일? ㅋㅋ

이기면 VICTORY 라고 뜨는것도 '킹덤러쉬'와 비슷하다.


솔직히, 완성도가 많이 떨어지고, 아류작같은 분위기가 나지만

플래시 게임에서 횡스크롤 액션게임이 별로 없었는데, 반가운 마음에 소개를 합니다.

게임은 여기서 ! http://www.kongregate.com/games/swartag/mighty-knight


노말(eliminate)모드 해봤는데, 너무 어렵다.
1분도 안되서 쥬금 ㅠㅠ
횡스크롤은 아닌듯. 맵이 딱 정혀져잇음;

데쓰모드는 더 어려울듯..

방향키 + 키보드 Z (공격), 마법은 x,c
대화창 뜨면 스페이스바 누르면 넘어갑니다. 즐겜!

갑자기 디아블로2 카우방 생각났어; 


끝판왕 보스 입니다.. 텔레포트를 자꾸하고 상당히 쎄다는


팁. 퀘스트 깨기가 힘들면, 했던거 또하고 또해서

돈 모은다음에 업그레이드 하고 진행하면 됩니다.


KMPlayer 지원하지 않는 오디오 코덱(DTA,AC3,E-AC3) 해결법

매우 좋은 프로그램이지만,
이런 에러 메세지가 나오기도 한다.


지원하지 않는 오디오 코덱(DTA,AC3,E-AC3)입니다.
자세한 사항은 포럼에서 확인하세요.

확인을 누르면, 코덱을 받을수 있는 사이트로 연결되어야 하는데,

http://player.kmpmedia.net/redirect/info_codec/?dummy=

페이지가 없는 상태이다.

아래 글에서 확인 할 수 있었는데, 윈도우8에서는 지원을 하고 있다고 한다.

http://forums.kmplayer.com/korea/showthread.php?p=13675
http://blog.naver.com/lshs0806/220234771522

AC3 Fileter 가 설치되어있는데도, 이런에러가 뜨는건
업데이트가 되면서 코덱유료문제?로 코덱이 빠진게 아닐까? 추측해본다.

환경설정에서 ALL Disable 만 해주면 정상작동하는것을 확인했다.


즐감!

2015년 1월 24일 토요일

jQuery 기본, 문서의 동작 확인하기 setTimeout , setInterval

http://jquery.com/

웹페이지가 준비되면 실행되는 제이쿼리 기본 문구이다.

$(document).ready(function(){

//TODO:

});

셑인터발 또는 셑타임아웃으로 간단하게 작동을 확인해보자.

$(document).ready(function(){

   start(); // 문서가 준비되면 start 함수를 실행한다.

   function start(){
      setTimeout(start,1000); // 1초 후 start를 재귀호출한다.
      console.log('hello~'); // 크롬 브라우저라면 F12를 눌러 확인할 수 있다.
      alert('hello~');
   }
});

이렇게하면, 계속 hello~ 를 한다.
어느정도 hello~ 를 하고나면 그만두게 하자.

hello~ 대신 시간을 찍어보자.
$(document).ready(function(){

 var watch; // 왓치라는 변수를 하나 만든다.
 
 function start(){
    watch = setTimeout(start,1000); //왓치변수에 재귀호출하는 행위를 넣는다.
    timer(); //타이머 함수를 불러온다.
 }

 function timer(){
  var d = new Date(); // 이번엔 시간을 찍어보자.
  var t = d.toLocaleTimeString(); // 우리말에 맞게 시간만 뽑아낸다.
  console.log(t);
 }
 
 function stop(){ // stop 이라는 함수는 6초후 
  setTimeout(function() { // 이름없는 함수를 호출하는 동작을 한다.
   clearTimeout(watch); // 재귀호출하는 watch 변수를 지운다.
  }, 6000);
 }

 start(); // start 함수 시작. 6초 동안 시간을 찍는다.
 stop(); // stop 함수 시작. 6초 후 시간 찍는것을 멈춘다.

});

setInterval 함수 역시 setTimeout 과 사용방법은 똑같다.

차이점은 setTimeout 은 한번만 실행되고 사라지기 때문에, 재귀함수로 계속 호출해줘야하지만 , setInterval 재귀함수 없이 밀리세컨드 간격으로 반복해서 실행하는것이 가능하다.

잘 이해가 안간다면 아래 소스와 위 소스 코드를 비교해보자.

$(document).ready(function(){

 var watch;
 
 function start(){
    watch = setInterval(timer,1000);
 }

 function timer(){
  var d = new Date();
  var t = d.toLocaleTimeString();
  console.log(t);
 }
 
 function stop(){
  setTimeout(function() {
   clearInterval(watch); // interval 함수 타이머 종료
  }, 6000);
 }
 start();
 stop();
});

버튼으로 만들면, 타이머를 만들 수 도 있다.

2015년 1월 17일 토요일

서브라임 텍스트 단축키

Preferences > Key Bindings > Default 를 선택하면
단축키 목록이 뜨는데, 사용자가 임의로 설정하여 저장할 수 있다.

전체 화면 : F11

한줄 주석/취소 : Ctrl + /

블럭 주석/취소 : Ctrl + Shift + /

현재라인을 한라인 위로 이동 : Ctrl + Shift + ↑

현재라인을 한라인 아래로 이동 : Ctrl + Shift + ↓

아래로 한라인 추가 : Ctrl + Enter

위로 한라인 추가 : Ctrl + Shift + Enter

현재라인 삭제 : Ctrl + Shift + K

현재라인을 바로 아래에 복사 : Ctrl + Shift + D

코드 펴기/접기 : Ctrl + Shift + ,

화면 나누기 : Shift + Alt + 1, 2, 3 ...

화면 이동 : Ctrl + 1, 2, 3 ...

같은 변수 한꺼번에 선택 편집 : Alt + F3

세로 선택 : Ctrl + Alt + ↑,↓ 또는 Shift + 마우스 우클릭 드래그

검색 : Ctrl + F

치환 : Ctrl + H

서브라임 텍스트 FTP 연결 방법

굉장히 좋은 프로그램이긴 한데,
클릭몇번으로 설정할 수 있는 친절한 프로그램은 아닌듯..
FTP 연결을 하려면 (파이썬)코드를 입력하여 플러그인을 설치해야하는데,
이건 뭐 외울수도 없고... 어디다 적어놔야 할판

Sublime Text SFTP 연결방법



1. CTRL + ~ 을 누르면 콘솔 입력창이 뜬다.



2. 아래 사이트에 가서 해당코드를 복사해 콘솔창에 붙여넣은 후 엔터.
버전별로 코드가 다르니 참고하도록..
https://packagecontrol.io/installation


3. 설치가 완료되면 Preferences > Package Control 이라는 메뉴가 생긴다.


4. 패키지콘트롤 선택 후 install package 라고 입력하고 엔터를 치면, 다시 메뉴가 뜨는데


5. sftp 라고 입력하면 항목이 뜨는데, sftp를 고르고 엔터를 치면, sftp 가 설치가 된다.


6. 설치가 완료되었으면, File > SFTP/FTP 메뉴가 생기는데 Setup Server 를 누른다.


7. File > Open Folder 로 폴더를 선택. View > Side Bar 로 사이드바를 보이게 한다.
CTRL + K,B 단축키로 사이드바를 보였다/숨겼다 할 수 있다.

8. 열린 폴더위에 마우스 우클릭 > SFTP/FTP > Map to Report 를 선택한다.


9. sftp-config.json 파일이 나오는데, 타입,포트,호스트,유저,비밀번호를 설정한다.


10. 그리고 파일을 저장을 하면 FTP 와 싱크 완료. 
로컬에서 파일을 저장하면 서버에도 저장된다.

*단점 : 유료다... 20달러, 서브라임 구매와 상관없이 사야한다.
등록하지 않으면 수시로 등록 권유 알림창이 뜬다.
sftp-config.json 에 일일이 등록유저의 이메일과 시리얼을 적어야한다.

플러터 단축키

1. 위젯 감싸기/벗기기 비주얼 스튜디오 :   Cmd + . 안드로이드 스튜디오 : Alt + Enter 2. 코드 정렬 비주얼 스튜디오 : Ctrl + S 안드로이드 스튜디오 : Ctlr + Alt + L 3. StatelessWidget ->...