<?php
require '../inc/func.php';
bk_head('Upload');
require '../inc/head.php';
include_once 'fun.php';
if (!$user) {
header ('location: /index.php');
exit;
}
$id = num($_GET['num']);
if(empty($id)){
header('location: index.php');
}
if(mysql_num_rows(mysql_query("SELECT * FROM album WHERE id ='$id' && user = '$userid'"))==0){
header('location: index.php');
exit;
}
echo '<div class="list1"><div class="tt"> '.$lng_up['upload'].'</div><div class="shadow">';
if(isset($_POST['save']) && $_FILES['photo']['size'] > 0){
$tmp = imagecreatefromstring(file_get_contents($_FILES['photo']['tmp_name']));
$type = $_FILES['photo']['type'];
$size = $_FILES['photo']['size'];
$fn = bk_check($_FILES['photo']['name']);
$fname = '' . time() . '_baka_' . $datauser['username'] . '.jpg';
$imgx = imagesx($tmp);
$imgy = imagesy($tmp);
#######mkdir folder
if(!is_dir('photos/'.$userid.'/ori') || !is_dir('photos/'.$userid.'/small') || !is_dir('photos/'.$userid.'/micro')){
if(!is_dir('photos/'.$userid.'')){
@mkdir("photos/".$userid."", 0777);
}
if(!is_dir('photos/'.$userid.'/ori')){
@mkdir("photos/".$userid."/ori", 0777);
}
if(!is_dir('photos/'.$userid.'/small')){
@mkdir("photos/".$userid."/small", 0777);
}
if(!is_dir('photos/'.$userid.'/micro')){
@mkdir("photos/".$userid."/micro", 0777);
}
}
###########
//ori size
$w=$imgx;
$h=$imgy;
if($w > 500 || $h > 500){
if($w>$h){
$o=$w/$h;
$ww=$w/500;
$w=$w/$ww;
$hh=$h/(500/$o);
$h=$h/$hh;
} else {
$o=$h/$w;
$hh=$h/500;
$h=$h/$hh;
$ww=$w/(500/$o);
$w=$w/$ww;
}
}
$img=imagecreatetruecolor($w,$h);
imagecopyresampled($img,$tmp,0,0,0,0,$w,$h,$imgx,$imgy);
$img = watermark($img);
$dir = 'photos/'.$userid.'/ori/'.$fname.'';
imagejpeg($img,$dir,95);
//small size
$w=$imgx;
$h=$imgy;
if($w > 150 || $h > 150){
if($w>$h){
$o=$w/$h;
$ww=$w/150;
$w=$w/$ww;
$hh=$h/(150/$o);
$h=$h/$hh;
} else {
$o=$h/$w;
$hh=$h/150;
$h=$h/$hh;
$ww=$w/(150/$o);
$w=$w/$ww;
}
}
$img=imagecreatetruecolor($w,$h);
imagecopyresampled($img,$tmp,0,0,0,0,$w,$h,$imgx,$imgy);
$img = watermark($img);
$dir = 'photos/'.$userid.'/small/'.$fname.'';
imagejpeg($img,$dir,95);
##micro size
$w=$imgx;
$h=$imgy;
if($w > 50 || $h > 50){
if($w>$h){
$o=$w/$h;
$ww=$w/50;
$w=$w/$ww;
$hh=$h/(50/$o);
$h=$h/$hh;
} else {
$o=$h/$w;
$hh=$h/50;
$h=$h/$hh;
$ww=$w/(50/$o);
$w=$w/$ww;
}
}
$img=imagecreatetruecolor($w,$h);
imagecopyresampled($img,$tmp,0,0,0,0,$w,$h,$imgx,$imgy);
$img = watermark($img);
$dir = 'photos/'.$userid.'/micro/'.$fname.'';
imagejpeg($img,$dir,95);
imagedestroy($img);
mysql_query("INSERT INTO `album_photo` SET `name` = '$fname', `album` = '$id', `time` = '" . time() . "', `user` = '$userid'");
if(isset($_POST['ava'])){
mysql_query("UPDATE users SET avatar ='$fname' WHERE id = '$userid'");
}
echo '<div class="notic">'.$lng_up['imgsuccess'].'<img src="photos/'.$userid.'/small/'.$fname.'" width="15%" /></div>';
}
?>
<form method="post" enctype="multipart/form-data"> Chỉ cho phép ảnh định dạng JPG, JPEG, PNG, GIF <br />
Chọn ảnh:<br /><input type="file" name="photo" accept="image/jpeg,image/png,image/gif" /><br />
<input type="checkbox" value="1" name="ava">Dùng avatar<br />
<input type="submit" name="save" value="OK" class="submit">
</form>
<font color="red">Lưu Ý:</font><br />
1. Dung lượng tối đa là 300kb..<br />
2. Tên tập tin gồm tiếng việt không dấu (a-Z, 0-9, _, -)..<br />
3. Hình ảnh sẽ bị xóa nếu nó là ảnh gây phản cảm, sex,...<br /></div>
<hr><div class="shadow"><a href="/users/my.php"><b>My Menu</b></a> | <a href="/u/<?php echo $userid ;?>"><b>Profile</b></a> | <a href="/exit.php"><b>LogOut</b></a></div>
</div>
<?php
bk_foot();
?>