Wlasnie o pomoc mi chodzi:)
doszedlem do wniosku ze z dodawaniem zdjec laczy sie kilka dokumentow i tak naprawde nie wiem w ktorym musze zrobic poprawki. Probowalem w sumie we wszystkich ale nic mi nie wyszlo:
glowny plik to:
<?php echo $form->create('Post',array('url'=>array
('controller'=>'front','action'=>'add'),'type'=>'file')); if(!$session->check('step2')):
if($session->check('img') and !$session->check('step2')):
?>
<img style="margin: 0 132px 30px;" src="
<?php echo $dir; ?>pic/sess/
<?php echo $session->read('img').'-1'.$session->read('hash').'.jpg'; ?>" />
<?php elseif(!$session->check('img') and !$session->check('step2')): ?>
<?php echo $form->input('Post.img',array('type'=>'file','label'=>'Obrazek','size'=>48
)); ?> <?php endif; ?>
<?php
echo $form->input('Post.title',array('label'=>'Tytuł','onmouseover'=>'this.focus();')); echo $form->input('Post.body',array('type'=>'textarea','label'=>'Opis','onmouseover'=>'this.focus();')); ?>
<div class="submit">
<?php if($session->check('img') and !$session->check('step2')): ?><input type="submit" name="data[Post][cancel1]" value="Wyczyść" /><?php endif; ?><input type="submit" name="submit" value="Dalej ť" />
</div>
</form>
</div>
<?php
else:
?>
<img src="
<?php $dir; ?>pic/sess/
<?php echo $session->read('img').'-2'.$session->read('hash').'.jpg'; ?>" />
<?php
$tags = $this->requestAction('front/randomTagCloud');
$tagCloud = $tag->create($tags);
$tagCloud = $tag->shuffleTags($tagCloud);
$cloud = null;
foreach($tagCloud as $tagName=>$tagValue) {
$cloud .=
"<a href='#' onClick='addTag(this); return false;' style='font-size:".$tagValue['size']."%; cursor: pointer;' title='".$tagName."'>".$tagName."</a> ";
}
($tags == false) ? $after = null: $after = '<br /><br />'.$cloud;
echo $form->input('Post.tag',array('label'=>'Tagi','between'=>'(rozdzielaj spacjami)<br />','after'=>$after, 'onmouseover'=>'this.focus();')); ?>
<div class="submit">
<input type="submit" name="data[Post][cancel2]" value="Ť Popraw" /><input type="submit" name="submit" value="Dodaj ť" />
</div>
</form>
<?php
endif;
$cloud;
?>
funkcja add: public function add() {
App::import('Sanitize');
$this->pageTitle .= ' - Dodaj';
if($this->data) {
$u = $this->Upload;
$s = $this->Session;
if(isset($this->data['Post']['cancel1'])) { @unlink(WWW_ROOT
.'pic/sess/'.$s->read('img').'-1'.$s->read('hash').'.jpg'); $this->Post->id =(int) $s->read('id');
$this->Post->delete();
$s->delete('step2');
$s->delete('id');
$s->delete('img');
$s->delete('hash');
$this->redirect($this->referer());
}
if(isset($this->data['Post']['cancel2'])) { @unlink(WWW_ROOT
.'pic/sess/'.$s->read('img').'-2'.$s->read('hash').'.jpg'); $s->del('step2');
return;
}
if((int)$s->read('Auth.User.active')===2) {
$s->setFlash('Twoje konto jest nieaktywne, potwierdź adres email.');
$this->redirect($this->referer());
}
$tag = trim($this->data['Post']['tag']);
if(!$s->check('step2')) {
if(!$s->check('img')) {
$u->upload($this->data['Post']['img']);
} else {
$u->upload(WWW_ROOT.'pic/sess/'.$s->read('img').'-1'.$s->read('hash').'.jpg');
}
if($u->uploaded) {
if($s->check('img')) {
$now = $s->read('img');
} else {
}
if($s->check('hash')) {
$hash = $s->read('hash');
} else {
$hash = $this->Pwd->alphaNumPass();
$s->write('hash',$hash);
}
$title = $this->data['Post']['title'];
$body = trim($this->data['Post']['body']); $body[0
] = trim($body[0
]); $_size = 0;
$_tsize = 0;
$_size += 19;
$_tsize += 11;
} elseif((bool
)(isset($body[1
]) and
!isset($body[2
]))) { $_size += 8;
}
$u->file_new_name_body = 'img';
$u->allowed = array('image/*'); $u->image_convert = 'png';
$u->image_resize = true;
$u->image_x = 440;
$u->image_safe_name = false;
$u->image_ratio_y = true;
$res = $u->process();
$img = imagecreatefromstring($res);
imagejpeg($img,WWW_ROOT.'pic/sess/'.$now.'-1'.$s->read('hash').'.jpg',100);
imagedestroy($img);
$u->allowed = array('image/*'); $u->image_convert = 'png';
$u->image_resize = true;
$u->image_x = 436;
$u->image_ratio_y = true;
$u->image_border_color = '#FFFFFF';
$u->image_border = '2px 2px 2px 2px';
$res = $u->process();
if($u->processed) {
$img = imagecreatefromstring($res);
$height = ($u->image_dst_y + 138);
$bg = imagecreatetruecolor(500,$height);
imagecopy($bg, $img,30,30,0,0,440,$height);
$black = imagecolorallocate($bg,0,0,0);
$white = imagecolorallocate($bg,255,255,255);
$font = WWW_ROOT.'fonts/DejaVuSerif.ttf';
$bbox = imagettfbbox(18,0,$font,$title);
$x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2);
$y = ($u->image_dst_y + 58 + $_tsize);
imagettftext($bg,18,0,$x,$y,$white,$font,$title);
$bbox = imagettfbbox(10,0,$font,$body[0]);
$x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2);
$y = ($u->image_dst_y + 78 + $_size);
imagettftext($bg,10,0,$x,$y,$white,$font,$body[0]);
$body[1
] = trim($body[1
]); $bbox = imagettfbbox(10,0,$font,$body[1]);
$x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2);
$y = ($u->image_dst_y + 96 + $_size);
imagettftext($bg,10,0,$x,$y,$white,$font,$body[1]);
}
$body[2
] = trim($body[2
]); $bbox = imagettfbbox(10,0,$font,$body[2]);
$x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2);
$y = ($u->image_dst_y + 114);
imagettftext($bg,10,0,$x,$y,$white,$font,$body[2]);
}
$gray = imagecolorallocate($bg,80,80,80);
$bbox = imagettfbbox(8,0,$font,$_SERVER['HTTP_HOST']);
$x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2);
$y = ($u->image_dst_y + 134);
imagettftext($bg,8,0,$x,$y,$gray,$font,$_SERVER['HTTP_HOST']);
imagejpeg($bg, WWW_ROOT.'pic/sess/'.$now.'-2'.$s->read('hash').'.jpg',100);
imagedestroy($img);
imagedestroy($bg);
if(!$s->check('id')) {
$this->Post->create();
} else {
$this->Post->id =(int) $s->read('id');
}
$this->Post->set('public',2);
'Post'=>array(
'id'=>$this->Post->id,
'user_id'=>$this->Session->read('Auth.User.id'),
'title'=>Sanitize::html($title),
'body'=>Sanitize::html($this->data['Post']['body']),
'img'=>'pic/'.$now.'-'.$hash.'.jpg'),
'public' => 2
)
);
$s->write('id',$this->Post->id);
$s->write('step2',true);
$s->write('img',$now);
return;
} else {
$s->setFlash('Nie można wgrać zdjęcia.');
return;
}
}
} else {
$u->upload(WWW_ROOT.'pic/sess/'.$s->read('img').'-2'.$s->read('hash').'.jpg');
if($u->uploaded) {
$u->image_convert = 'jpg';
$u->jpeg_quality = 100;
$u->file_safe_name = false;
$u->file_new_name_body = $s->read('img').'-'.$s->read('hash');
$u->process(WWW_ROOT.'/pic/');
if($u->processed) {
@unlink(WWW_ROOT
.'pic/sess/'.$s->read('img').'-1'.$s->read('hash').'.jpg'); @unlink(WWW_ROOT
.'pic/sess/'.$s->read('img').'-2'.$s->read('hash').'.jpg'); $this->Post->id =(int) $s->read('id');
$this->Post->set('public', 0);
$this->Post->set('created',date('Y-m-d H:i:s',strtotime('now'))); $this->Post->set('modified',date('Y-m-d H:i:s',strtotime('now'))); $this->Post->save();
foreach($tag as $k=>$v) {
if($k==(int) $this->getOpt('max_tags'))
break;
$t = $this->Tag->findByName($v);
if($t) {
$this->PostsTag->create();
$this->Tag->id=$t['Tag']['id'];
$this->Tag->save(array('Tag'=>array
('post_count'=>($t['Tag']['post_count']+1
)))); $this->PostsTag->save(array('PostsTag'=>array
('post_id'=>$this->Post->id,'tag_id'=>$t['Tag']['id']))); continue;
}
$this->Tag->create();
$this->Tag->save(array('Tag'=>array
('name'=>trim
($v),'post_count'=>1
))); $this->PostsTag->create();
$this->PostsTag->save(array('PostsTag'=>array
('post_id'=>$this->Post->id,'tag_id'=>$this->Tag->id))); }
}
$s->del('id');
$s->del('step2');
$s->del('img');
$s->del('hash');
$this->redirect('/view/'.$this->Post->id);
}
}
}
}
}
Ponadto jest jeszcze dlugi plik o nazwie "upload",ale nie wiem czy jest on niezbedny. Probowalem to kopiowac, dodawac podobna funkcje add2 itp. ale nie przynioslo to skutku.