仿discuz 上传头像
1. [图片] ]6H2)I{}EKG4GC2RN_%[5_A.jpg
2. [代码][PHP]代码
<?php class AvatarUploader { // ? url private function getThisUrl() { $thisUrl = $_SERVER['SCRIPT_NAME']; $thisUrl = "http://{$_SERVER['HTTP_HOST']}{$thisUrl}"; return $thisUrl; } // ? base-url / private function getBaseUrl() { $baseUrl = $this->getThisUrl(); $baseUrl = substr( $baseUrl, 0, strrpos( $baseUrl, '/' ) + 1 ); return $baseUrl; } // ???? DIRECTORY_SEPARATOR private function getBasePath() { $basePath = $_SERVER['SCRIPT_FILENAME']; $basePath = substr( $basePath, 0, strrpos($basePath, '/' ) + 1 ); $basePath = str_replace( '/', DIRECTORY_SEPARATOR, $basePath ); return $basePath; } // ??????? private function uploadAvatar( $uid ) { // ?? if ( empty($_FILES['Filedata']) ) { return -3; // No photograph be upload! } // ? $tmpPath = $this->getBasePath() . "data" . DIRECTORY_SEPARATOR . "{$uid}"; // ???? $dir = dirname( $tmpPath ); if ( !file_exists( $dir ) ) { @mkdir( $dir, 0777, true ); } // ?????? if ( file_exists($tmpPath) ) { @unlink($tmpPath); } // ????? if ( @copy($_FILES['Filedata']['tmp_name'], $tmpPath) || @move_uploaded_file($_FILES['Filedata']['tmp_name'], $tmpPath)) { @unlink($_FILES['Filedata']['tmp_name']); list($width, $height, $type, $attr) = getimagesize($tmpPath); if ( $width < 10 || $height < 10 || $width > 3000 || $height > 3000 || $type == 4 ) { @unlink($tmpPath); return -2; // Invalid photograph! } } else { @unlink($_FILES['Filedata']['tmp_name']); return -4; // Can not write to the data/tmp folder! } // ????? url $tmpUrl = $this->getBaseUrl() . "data/{$uid}"; return $tmpUrl; } private function flashdata_decode($s) { $r = ''; $l = strlen($s); for($i=0; $i<$l; $i=$i+2) { $k1 = ord($s[$i]) - 48; $k1 -= $k1 > 9 ? 7 : 0; $k2 = ord($s[$i+1]) - 48; $k2 -= $k2 > 9 ? 7 : 0; $r .= chr($k1 << 4 | $k2); } return $r; } // ????? private function rectAvatar( $uid ) { // $_POST ??? $bigavatar = $this->flashdata_decode( $_POST['avatar1'] ); $middleavatar = $this->flashdata_decode( $_POST['avatar2'] ); $smallavatar = $this->flashdata_decode( $_POST['avatar3'] ); if ( !$bigavatar || !$middleavatar || !$smallavatar ) { return '<root><message type="error" value="-2" /></root>'; } // ???? $bigavatarfile = $this->getBasePath() . "data" . DIRECTORY_SEPARATOR . "{$uid}_big.jpg"; $middleavatarfile = $this->getBasePath() . "data" . DIRECTORY_SEPARATOR . "{$uid}_middle.jpg"; $smallavatarfile = $this->getBasePath() . "data" . DIRECTORY_SEPARATOR . "{$uid}_small.jpg"; $success = 1; $fp = @fopen($bigavatarfile, 'wb'); @fwrite($fp, $bigavatar); @fclose($fp); $fp = @fopen($middleavatarfile, 'wb'); @fwrite($fp, $middleavatar); @fclose($fp); $fp = @fopen($smallavatarfile, 'wb'); @fwrite($fp, $smallavatar); @fclose($fp); // ????? $biginfo = @getimagesize($bigavatarfile); $middleinfo = @getimagesize($middleavatarfile); $smallinfo = @getimagesize($smallavatarfile); if ( !$biginfo || !$middleinfo || !$smallinfo || $biginfo[2] == 4 || $middleinfo[2] == 4 || $smallinfo[2] == 4 ) { file_exists($bigavatarfile) && unlink($bigavatarfile); file_exists($middleavatarfile) && unlink($middleavatarfile); file_exists($smallavatarfile) && unlink($smallavatarfile); $success = 0; } // ???? $tmpPath = $this->getBasePath() . "data" . DIRECTORY_SEPARATOR . "{$uid}"; @unlink($tmpPath); return '<?xml version="1.0" ?><root><face success="' . $success . '"/></root>'; } // ?????? url public function getAvatarUrl( $uid, $size='middle' ) { return $this->getBaseUrl() . "data/{$uid}_{$size}.jpg"; } // HTTP Request // ??? request?? true?? false public function processRequest() { // input ? $arr = array(); parse_str( $_GET['input'], $arr ); $uid = intval($arr['uid']); if ( $_GET['a'] == 'uploadavatar') { // ??????? echo $this->uploadAvatar( $uid ); return true; } else if ( $_GET['a'] == 'rectavatar') { // ????? echo $this->rectAvatar( $uid ); return true; } return false; } // ?? camera.swf HTML public function renderHtml( $uid ) { // ???? input $input = urlencode( "uid={$uid}" ); $baseUrl = $this->getBaseUrl(); $uc_api = urlencode( $this->getThisUrl() ); $urlCameraFlash = "{$baseUrl}camera.swf?ucapi={$uc_api}&input={$input}"; $urlCameraFlash = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="447" height="477" id="mycamera" align="middle"> <param name="allowScriptAccess" value="always" /> <param name="scale" value="exactfit" /> <param name="wmode" value="transparent" /> <param name="quality" value="high" /> <param name="bgcolor" value="#ffffff" /> <param name="movie" value="'.$urlCameraFlash.'" /> <param name="menu" value="false" /> <embed src="'.$urlCameraFlash.'" quality="high" bgcolor="#ffffff" width="447" height="477" name="mycamera" align="middle" allowScriptAccess="always" allowFullScreen="false" scale="exactfit" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>'; return $urlCameraFlash; } } header("Expires: 0"); header("Cache-Control: private, post-check=0, pre-check=0, max-age=0", FALSE); header("Pragma: no-cache"); header("Cache-Control:no-cache"); $au = new AvatarUploader(); if ( $au->processRequest() ) { exit(); } // ???? camera.swf $uid = intval($_GET['uid']); $urlAvatarBig = $au->getAvatarUrl( $uid, 'big' ); $urlAvatarMiddle = $au->getAvatarUrl( $uid, 'middle' ); $urlAvatarSmall = $au->getAvatarUrl( $uid, 'small' ); $urlCameraFlash = $au->renderHtml( $uid ); ?> <script type="text/javascript"> function updateavatar() { window.location.reload(); } </script> <img src="<?php echo $urlAvatarBig ?>"> <img src="<?php echo $urlAvatarMiddle ?>"> <img src="<?php echo $urlAvatarSmall ?>"> <hr> <?php echo $urlCameraFlash ?>
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
어 ass 신 크리드 그림자 : 조개 수수께끼 솔루션
1 몇 주 전ByDDD
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

드림위버 CS6
시각적 웹 개발 도구

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

뜨거운 주제
Cakephp 튜토리얼
1375
52


Win11 활성화 키 영구
40
19

