Permalink
Browse files

fix photos

  • Loading branch information...
1 parent 69f21af commit 0f296ca493b01b9c29b59d6458e9dfe1952b8b3b @furtherLee committed Jun 1, 2012
View
@@ -1,4 +1,5 @@
.classpath
*.DS_Store
*~
+image/user_*.jpg
View
@@ -1,7 +1,11 @@
+all: sessions image
sessions:
mkdir /tmp/sessions
chmod 777 /tmp/sessions
+image:
+ chmod 777 image
+
@@ -5,7 +5,8 @@ class Controller{
"HOST_URL" => HOST_URL,
"JS_HOME" => JS_HOME,
"CSS_HOME" => CSS_HOME,
- "IMG_HOME" => IMG_HOME
+ "IMG_HOME" => IMG_HOME,
+ "IMAGE_HOME" => IMAGE_HOME
);
protected function render($name, $context){
@@ -42,6 +42,7 @@ public function newGroup(){
$group->setName(fRequest::get("name"));
$group->setLeader(fRequest::get("leader-id"));
$group->setDesp(fRequest::get("desp"));
+ $group->setPhoto(fRequest::get("photo"));
$group->store();
$member = new Member();
$member->setUid($this->getUser()->getId());
@@ -0,0 +1,19 @@
+<?php
+class ImageController extends Controller{
+ public function uploadAvatar(){
+ $str = uniqid('user_');
+ if (self::isImage($_FILES['avatar-file'])){
+ move_uploaded_file($_FILES['avatar-file']['tmp_name'], IMAGE_PATH.$str.".jpg");
+ $this->ajaxReturn(array('status' => 'ok', 'path' => "$str.jpg"));
+ }
+ else{
+ $this->ajaxReturn(array('status' => 'error', 'message' => 'cannot save your image file'), 400);
+ }
+ }
+
+ protected static function isImage($f)
+ {
+ return $f['type'] == 'image/jpeg' || $f['type'] == 'image/pjpeg';
+ }
+
+}
@@ -90,6 +90,8 @@ public function register(){
$user->setBirthday(fRequest::get('birthday'));
+ $user->setPhoto(fRequest::get('photo'));
+
$user->store();
$this->ajaxReturn(array(
View
@@ -26,6 +26,8 @@
require_once(__DIR__.'/controllers/GroupController.php');
require_once(__DIR__.'/controllers/WorkController.php');
require_once(__DIR__.'/controllers/ScheduleController.php');
+require_once(__DIR__.'/controllers/ImageController.php');
+
/**
* Set Up Routes
*/
View
@@ -104,4 +104,9 @@
$controller->search();
});
+$app->post('/upload/', function(){
+ $controller = new ImageController();
+ $controller->uploadAvatar();
+ });
+
$app->run();
@@ -12,5 +12,9 @@
{% block js %}
{{ parent() }}
+<script type="text/javascript" src="{{JS_HOME}}jquery.ui.widget.js"></script>
+<script type="text/javascript" src="{{JS_HOME}}jquery.iframe-transport.js"></script>
+<script type="text/javascript" src="{{JS_HOME}}jquery.fileupload.js"></script>
+<script type="text/javascript" src="{{JS_HOME}}widgets.js"></script>
<script type="text/javascript" src="{{JS_HOME}}group_create.js"></script>
{% endblock %}
@@ -24,7 +24,13 @@
<textarea rows="10" placeholder="..." name="desp" class="input-xlarge focused"></textarea>
</div>
</div>
-
+ <div class="control-group">
+ <label for="photo" class="control-label">头像</label>
+ <div class="controls">
+ <input type="hidden" id="input-photo" name="photo" value="defaultGroup.jpg"/>
+ <button class="btn btn-info input-xlarge" id="upload-img">上传头像</button>
+ </div>
+ </div>
<div class="control-group">
<div class="controls">
<a class="btn btn-primary input-small pull-left" id="submit" id="submit" style="margin-right: 30px;">提交</a>
@@ -1,6 +1,6 @@
<div class="well span7 container group_info_background">
<div class="container span2">
- <img src="{{IMG_HOME}}group.jpg"/>
+ <img src="{{IMAGE_HOME}}{{group.getPhoto()}}"/>
</div>
<div class="span5">
<p class="group_info_title">
@@ -2,7 +2,7 @@
<div class="row">
<div class="span2">
<a class="thumbnail">
- <img src="{{IMG_HOME}}group.jpg"/>
+ <img src="{{IMAGE_HOME}}{{group.getPhoto()}}"/>
</a>
</div>
<div class="span4">
@@ -13,7 +13,7 @@
{{group.getDesp()|e}}
</passage>
<div class="group-buttons">
- <a class="join-group" data="{{group.getId()}}">加入小组</a>
+ <a class="join-group" data="{{group.getId()}}" href="#">加入小组</a>
<a href="{{HOST_URL}}/group/{{group.getId()}}/">浏览小组</a>
</div>
</div>
@@ -7,7 +7,7 @@
<ul >
<div class="group_pl_plane">
<div class="span1 container">
- <img src="{{IMG_HOME}}photo.png" class="little_pic"/>
+ <img src="{{IMAGE_HOME}}{{leader.getPhoto()}}" class="little_pic"/>
</div>
<div class="span2 container group_pl_user">
<p class="group_pl_name">姓名: {{leader.getName()}}</p>
@@ -25,7 +25,7 @@
{% for mem in members%}
<div class="group_pl_plane">
<div class="span1 container">
- <img src="{{IMG_HOME}}photo.png" class="little_pic"/>
+ <img src="{{IMAGE_HOME}}{{mem.getPhoto()}}" class="little_pic"/>
</div>
<div class="span2 container group_pl_user">
<p class="group_pl_name">姓名: {{mem.getName()}}</p>
@@ -1,7 +1,7 @@
<div class="well span4" id="profile-type">
<div class="span4" id="profile-photo">
<a href="#" class="thumbnail">
- <img src="{{IMG_HOME}}photo.png"/>
+ <img src="{{IMAGE_HOME}}{{user.getPhoto()}}"/>
</a>
</div>
<div style="padding: 8px 0;" class="span4 well" id="profile-info">
@@ -17,61 +17,72 @@
</a>
</div>
<div class="span6">
- <div class="table">
- <form id="register-form" class="form-horizontal">
- <fieldset>
- <div class="control-group">
- <label for="name" class="control-label">昵称</label>
- <div class="controls">
- <input type="text" placeholder="新建哥" name="name" class="input-xlarge focused"/>
+ <div class="table">
+ <form id="register-form" class="form-horizontal">
+ <fieldset>
+ <div class="control-group">
+ <label for="name" class="control-label">昵称</label>
+ <div class="controls">
+ <input type="text" placeholder="新建哥" name="name" class="input-xlarge focused"/>
+ </div>
</div>
- </div>
- <div class="control-group">
- <label for="email" class="control-label">邮箱地址</label>
- <div class="controls">
- <input type="text" placeholder="Example@example.com" name="email" class="input-xlarge focused"/>
+ <div class="control-group">
+ <label for="email" class="control-label">邮箱地址</label>
+ <div class="controls">
+ <input type="text" placeholder="Example@example.com" name="email" class="input-xlarge focused"/>
+ </div>
</div>
- </div>
- <div class="control-group">
- <label for="password" class="control-label">密码</label>
- <div class="controls">
- <input type="password" placeholder="*****" name="password" class="input-xlarge focused"/>
+ <div class="control-group">
+ <label for="password" class="control-label">密码</label>
+ <div class="controls">
+ <input type="password" placeholder="*****" name="password" class="input-xlarge focused"/>
+ </div>
</div>
- </div>
- <div class="control-group">
- <label for="passwordagain" class="control-label">密码重复</label>
- <div class="controls">
- <input type="password" placeholder="*****" name="passwordagain" class="input-xlarge focused"/>
+ <div class="control-group">
+ <label for="passwordagain" class="control-label">密码重复</label>
+ <div class="controls">
+ <input type="password" placeholder="*****" name="passwordagain" class="input-xlarge focused"/>
+ </div>
</div>
- </div>
- <div class="control-group">
- <label for="sex" class="control-label">性别</label>
- <div class="controls">
- <select name="sex" class="input-xlarge">
- <option></option>
- <option>女</option>
- </select>
+ <div class="control-group">
+ <label for="sex" class="control-label">性别</label>
+ <div class="controls">
+ <select name="sex" class="input-xlarge">
+ <option>男</option>
+ <option></option>
+ </select>
+ </div>
</div>
- </div>
- <div class="control-group">
- <label for="birthday" class="control-label">出生年月</label>
- <div class="controls">
- <input type="date" name="birthday" class="input-xlarge"/>
+ <div class="control-group">
+ <label for="birthday" class="control-label">出生年月</label>
+ <div class="controls">
+ <input type="date" name="birthday" class="input-xlarge"/>
+ </div>
</div>
- </div>
- <div id="registbtnpos">
- <button class="btn btn-primary pull-left input-middle" id="submit" type="submit">注册</button>
- <a class="btn pull-left input-middle" href="{{HOST_URL}}">取消</a>
- </div>
- </fieldset>
- </form>
- </div>
+ <div class="control-group">
+ <label for="photo" class="control-label">头像</label>
+ <div class="controls">
+ <input type="hidden" id="input-photo" name="photo" value="defaultUser.jpg"/>
+ <button class="btn btn-info input-xlarge" id="upload-img">上传头像</button>
+ </div>
+ </div>
+ <div id="registbtnpos">
+ <button class="btn btn-primary pull-left input-middle" id="submit" type="submit">注册</button>
+ <a class="btn pull-left input-middle" href="{{HOST_URL}}">取消</a>
+ </div>
+ </fieldset>
+ </form>
+ </div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block js %}
+<script type="text/javascript" src="{{JS_HOME}}jquery.ui.widget.js"></script>
+<script type="text/javascript" src="{{JS_HOME}}jquery.iframe-transport.js"></script>
+<script type="text/javascript" src="{{JS_HOME}}jquery.fileupload.js"></script>
+<script type="text/javascript" src="{{JS_HOME}}widgets.js"></script>
<script type="text/javascript" src="{{JS_HOME}}register.js"></script>
{% endblock %}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 0f296ca

Please sign in to comment.