asimryu

upload.php for indexedDB - 친구 추가,수정,삭제, 사진추가 및 base64 업로드 포함

Dec 5th, 2017
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2. $photo = "";
  3. $result = "false";
  4. if( isset($_POST['photo']) ) $photo = $_POST['photo'];
  5. if( $photo && substr($photo, 0, 10) == "data:image" ) {
  6.     //base64 코드 이미지를 분석해서 파일 종류를 구분하여 확장자 얻어내기
  7.     //data:image/png;base64,iVBORw0KGgoAA...5CYII=
  8.     $src = explode(',', $photo);
  9.     $imghead = explode(';', $src[0]);
  10.     $imgformat = explode('/', $imghead[0]);
  11.     $imgext = $imgformat[1];
  12.     if( $imgext =="jpeg" ) $imgext = "jpg";
  13.     $imgdata = base64_decode($src[1]);
  14.     $imgfile = date("YmdHis") . "." . $imgext;
  15.     $imgpath = "photo/" . $imgfile;
  16.     if( file_put_contents($imgpath,$imgdata) ) {
  17.         $result = "true";
  18.     }
  19. }
  20. echo $result;
Advertisement
Add Comment
Please, Sign In to add comment