예제 #1
0
 public function upfile()
 {
     import('ORG.Util.Crop');
     $id = $this->_session('id');
     $file_name = 'sunyang';
     $crop = new CropAvatar($_POST['avatar_src'], $_POST['avatar_data'], $_FILES['avatar_file'], $id);
     $response = array('state' => 200, 'message' => $crop->getMsg(), 'result' => $crop->getResult());
     echo json_encode($response);
     //$this->redirect('User/index');
     /*
     $path = APP_PATH."avatar/";
     $id = $this->_session('id');
     $file_src = "src.png";
     $filename162 = $id.".png";
     $filename48 = $id."_2.png";
     $filename20 = $id."_3.png";
     
     $src=base64_decode($_POST['pic']);
     $pic1=base64_decode($_POST['pic1']);
     $pic2=base64_decode($_POST['pic2']);
     $pic3=base64_decode($_POST['pic3']);
     
     if($src) {
     file_put_contents($file_src,$src);
     }
     
     file_put_contents($path.$filename162,$pic1);
     file_put_contents($path.$filename48,$pic2);
     file_put_contents($path.$filename20,$pic3);
     
     $rs['status'] = 1;
     
     echo json_encode($rs);
     */
 }
예제 #2
0
 public function execute()
 {
     $user = $this->getUser();
     // Blocked users cannot submit new comments, and neither can those users
     // without the necessary privileges. Also prevent obvious cross-site request
     // forgeries (CSRF)
     if (wfReadOnly()) {
         $responseBody = array('state' => 200, 'message' => '本维基处于只读状态。', 'result' => $avatar->getResult());
         $result = $this->getResult();
         $result->addValue($this->getModuleName(), 'res', $responseBody);
         return true;
     } elseif (!$user->isAllowed('upload')) {
         $responseBody = array('state' => 200, 'message' => '您没有上传头像的权限。您是否未验证邮箱?', 'result' => $avatar->getResult());
         $result = $this->getResult();
         $result->addValue($this->getModuleName(), 'res', $responseBody);
         return true;
     } elseif ($user->isBlocked()) {
         $responseBody = array('state' => 200, 'message' => '您已被封禁。', 'result' => $avatar->getResult());
         $result = $this->getResult();
         $result->addValue($this->getModuleName(), 'res', $responseBody);
         return true;
     }
     $avatar_src = $this->getMain()->getVal('avatar_src');
     $avatar_data = $this->getMain()->getVal('avatar_data');
     $avatar_file = $this->getMain()->getUpload('avatar_file');
     $avatar = new CropAvatar($avatar_src, $avatar_data, $avatar_file);
     $responseBody = array('state' => 200, 'message' => $avatar->getMsg(), 'result' => $avatar->getResult());
     $result = $this->getResult();
     $result->addValue($this->getModuleName(), 'res', $responseBody);
     return true;
 }
예제 #3
0
                break;
            case UPLOAD_ERR_EXTENSION:
                $message = 'File upload stopped by extension';
                break;
            default:
                $message = 'Unknown upload error';
        }
        return $message;
    }
    public function getResult()
    {
        if (!empty($this->data)) {
            $url = $this->host . 'photos/' . basename($this->dst);
            $curr_time = time();
            $curr_gmt_date = gmdate('Y-m-d H:i:s', $curr_time);
            unlink('img/' . basename($this->src));
            $insertQry = "insert into photos (Entity_Id, Photo_Url, Post_Dt, Share_Opt) values ('1556','" . $url . "', '" . $curr_gmt_date . "', '2')";
            mysql_query($insertQry, $this->db->conn);
            return '../photos/' . basename($url);
        } else {
            return '';
        }
    }
    public function getMsg()
    {
        return $this->msg;
    }
}
$crop = new CropAvatar($_POST['avatar_src'], $_POST['avatar_data'], $_FILES['avatar_file']);
$response = array('state' => 200, 'message' => $crop->getMsg(), 'result' => $crop->getResult());
echo json_encode($response);
예제 #4
0
                break;
            case UPLOAD_ERR_NO_FILE:
                $message = 'No file was uploaded';
                break;
            case UPLOAD_ERR_NO_TMP_DIR:
                $message = 'Missing a temporary folder';
                break;
            case UPLOAD_ERR_CANT_WRITE:
                $message = 'Failed to write file to disk';
                break;
            case UPLOAD_ERR_EXTENSION:
                $message = 'File upload stopped by extension';
                break;
            default:
                $message = 'Unknown upload error';
        }
        return $message;
    }
    public function getResult()
    {
        return !empty($this->data) ? $this->dst : $this->src;
    }
    public function getMsg()
    {
        return $this->msg;
    }
}
$file_name = date('YmdHis');
$crop = new CropAvatar($_POST['avatar_src'], $_POST['avatar_data'], $_FILES['avatar_file'], $file_name);
$response = array('state' => 200, 'message' => $crop->getMsg(), 'result' => $crop->getResult(), 'img_name' => date('YmdHis') . '.png');
echo json_encode($response);
예제 #5
0
                $message = 'The uploaded file was only partially uploaded';
                break;
            case UPLOAD_ERR_NO_FILE:
                $message = 'No file was uploaded';
                break;
            case UPLOAD_ERR_NO_TMP_DIR:
                $message = 'Missing a temporary folder';
                break;
            case UPLOAD_ERR_CANT_WRITE:
                $message = 'Failed to write file to disk';
                break;
            case UPLOAD_ERR_EXTENSION:
                $message = 'File upload stopped by extension';
                break;
            default:
                $message = 'Unknown upload error';
        }
        return $message;
    }
    public function getResult()
    {
        return !empty($this->data) ? $this->dst : $this->src;
    }
    public function getMsg()
    {
        return $this->msg;
    }
}
$crop = new CropAvatar($_POST['avatar_src'], $_POST['avatar_data'], $_FILES['avatar_file']);
$response = ['state' => 200, 'message' => $crop->getMsg(), 'result' => $crop->getResult()];
echo json_encode($response);
예제 #6
0
                $message = 'The uploaded file was only partially uploaded';
                break;
            case UPLOAD_ERR_NO_FILE:
                $message = 'No file was uploaded';
                break;
            case UPLOAD_ERR_NO_TMP_DIR:
                $message = 'Missing a temporary folder';
                break;
            case UPLOAD_ERR_CANT_WRITE:
                $message = 'Failed to write file to disk';
                break;
            case UPLOAD_ERR_EXTENSION:
                $message = 'File upload stopped by extension';
                break;
            default:
                $message = 'Unknown upload error';
        }
        return $message;
    }
    public function getResult()
    {
        return !empty($this->data) ? $this->dst : $this->src;
    }
    public function getMsg()
    {
        return $this->msg;
    }
}
$crop = new CropAvatar($_POST['avatar_src'], $_POST['avatar_data'], $_FILES['avatar_file']);
$response = array('state' => 200, 'message' => $crop->getMsg(), 'result' => URL::to('/') . '/' . $crop->getResult());
 function uploadcrop()
 {
     $crop = new CropAvatar(isset($_POST['avatar_src']) ? $_POST['avatar_src'] : null, isset($_POST['avatar_data']) ? $_POST['avatar_data'] : null, isset($_FILES['avatar_file']) ? $_FILES['avatar_file'] : null);
     $response = array('state' => 200, 'message' => $crop->getMsg(), 'result' => $crop->getResult());
     echo json_encode($response);
     die;
 }
예제 #8
0
        return !empty($this->data) ? $this->dst : $this->src;
    }
    public function getMsg()
    {
        return $this->msg;
    }
}
$crop = new CropAvatar(isset($_POST['avatar_src']) ? $_POST['avatar_src'] : null, isset($_POST['avatar_data']) ? $_POST['avatar_data'] : null, isset($_FILES['avatar_file']) ? $_FILES['avatar_file'] : null);
/*
$response = array(
  'state'  => 200,
  'message' => $crop -> getMsg(),
  'result' => $crop -> getResult()
);
*/
$sql = "INSERT INTO photos (name_file) values (:name_file)";
$conn = getConn();
$stmt = $conn->prepare($sql);
$stmt->bindParam("name_file", $crop->getResult());
$stmt->execute();
$id = $conn->lastInsertId();
if ($id != NULL) {
    $response["state"] = 200;
    $response["status"] = "success";
    $response["message"] = "Foto adicionada";
    $response["result"] = $id;
} else {
    $response["status"] = "error";
    $response["message"] = "Erro ao adicionar a foto";
}
echo json_encode($response);