<?php
$uid =$_request[' uid '];
$avatar = ' d:/avic/discuz/uc_server/data/avatar/'. Get_avatar ($uid, $size, $type);
$dir =dirname ($avatar);
//Create directory After success move temporary file
if (mkdirs ($dir)) {
if ($_files["pic"] ["error"] >= 0) {
if (move_uploaded_file $_files [' Pic '] [' Tmp_name '], $avatar)) {
$errorcode =1;
}else{
$errorcode =0;
$errormsg = "File move Failed";
}
}else{
$errorcode =0;
$errormsg =$_files[' pic '] [' ERROR '];
}
$back =array ("ErrorCode" => $errorcode, ' errormsg ' => $errormsg);
echo Json_encode ($back);
//Returns the path to be stored by the picture
function Get_avatar ($uid, $size = ' middle ', $type = ') {
$size = In_array ($size, Array (' Big ', ' mi Ddle ', ' small ')? $size: ' Middle ';
$uid = ABS (Intval ($UID));
$uid = sprintf ("%09d", $uid);
$dir 1 = substr ($uid, 0, 3);
$dir 2 = substr ($uid, 3, 2);
$dir 3 = substr ($uid, 5, 2);
$typeadd = $type = = ' REAL '? ' _real ': ';
return $dir 1. ' /'. $dir 2. ' /'. $dir 3. ' /'. substr ($uid,-2). $typeadd. " _avatar_$size.jpg ";
}
///recursively create a directory, if the $dir is not an absolute path, then the directory that runs this method
function mkdirs ($dir) {
if (!is_dir ($dir)) {
If!mkdirs ( DirName ($dir))) {
return false;
if (!mkdir ($dir, 0777)) {
return false;
}
return true;
}
?