function upload in photos_controller:
function upload()
{
$this->authorize();
$user = $this->User->findById($this->user['id']);
if(!($user && ($user['User']['photos_limit'] == 0 || $user['User']['photos'] < $user['User']['photos_limit'])))
{
exit('You reached your upload limit');
}
else
{
$fileParts = $_FILES['Filedata']['name'];
$secret = $this->generateRandomString(20);
$name = str_replace(array('.jpg', '.jpeg', '.JPG', '.JPEG', '.png', '.PNG'), '', $fileParts);
if($this->Photo->save(array('Photo' => array('name' => $name, 'user_id' => $this->user['id'], 'secret' => $secret, 'hidden' => 0, 'privacy' => array_search($_GET['privacy'], Configure::read('Site.privacy'))))))
{
$this->User->query('UPDATE fociki_users' .
' SET photos = photos + 1' .
', last_public_photo = (SELECT created FROM fociki_photos WHERE user_id = ' . $this->user['id'] . ' AND fociki_photos.privacy <= ' . array_search('public', Configure::read('Site.privacy')) .' ORDER BY created DESC LIMIT 1)' .
', last_friend_photo = (SELECT created FROM fociki_photos WHERE user_id = ' . $this->user['id'] . ' AND fociki_photos.privacy <= ' . array_search('friend', Configure::read('Site.privacy')) .' ORDER BY created DESC LIMIT 1)' .
' WHERE id = ' . $this->user['id']);
$original_file = $this->Photo->getOriginalFile($this->Photo->id, $secret, true);
$original_file_path = $original_file->pwd();
$tempFile = $_FILES['Filedata']['tmp_name'];
move_uploaded_file($tempFile, $original_file_path);
exec('/usr/bin/convert -geometry 400x350 ' . $original_file_path . ' ' . $this->Photo->getMediumFile($this->Photo->id, $secret)->pwd() .' > /dev/null 2>&1 &');
exec('/usr/bin/convert -geometry 145x145 ' . $original_file_path . ' ' . $this->Photo->getSmallFile($this->Photo->id, $secret)->pwd() .' > /dev/null 2>&1 &');
exec('/usr/bin/convert -thumbnail x150 -resize "150x<" -resize 50% -gravity center -crop 75x75+0+0 +repage ' . $original_file_path . ' ' . $this->Photo->getSquareFile($this->Photo->id, $secret)->pwd() .' > /dev/null 2>&1 &');
exec('/usr/bin/convert -thumbnail x96 -resize "96x<" -resize 50% -gravity center -crop 48x48+0+0 +repage ' . $original_file_path . ' ' . $this->Photo->getBuddyFile($this->Photo->id, $secret)->pwd() .' > /dev/null 2>&1 &');
exec('/usr/bin/convert -geometry 500x450 ' . $original_file_path . ' ' . $this->Photo->getLargeFile($this->Photo->id, $secret)->pwd() .' > /dev/null 2>&1 &');
}
echo 'OK';
die();
}
}
and here is the Model photo.php
<?php
class Photo extends AppModel {
var $name = 'Photo';
var $validate = array(
'user_id' => array(
'rule' => 'notEmpty'
),
'name' => array(
'rule' => 'notEmpty'
),
);
var $belongsTo = 'User';
var $hasMany = array(
'PhotoTag' => array('order' => array('tag' => 'ASC')),
'PhotoNote' => array('order' => array('created' => 'ASC')),
);
function getOriginalFile($id, $secret, $create = null, $chmod = null)
{
return new File(WWW_ROOT . 'photos' . DS . 'original' . DS . $id . '-' . $secret . '.jpg', $create, $chmod);
}
function getLargeFile($id, $secret, $create = null, $chmod = null)
{
return new File(WWW_ROOT . 'photos' . DS . 'large' . DS . $id . '-' . $secret . '.jpg', $create, $chmod);
}
function getMediumFile($id, $secret, $create = null, $chmod = null)
{
return new File(WWW_ROOT . 'photos' . DS . 'medium' . DS . $id . '-' . $secret . '.jpg', $create, $chmod);
}
function getSmallFile($id, $secret, $create = null, $chmod = null)
{
return new File(WWW_ROOT . 'photos' . DS . 'small' . DS . $id . '-' . $secret . '.jpg', $create, $chmod);
}
function getThumbFile($id, $secret, $create = null, $chmod = null)
{
return new File(WWW_ROOT . 'photos' . DS . 'thumb' . DS . $id . '-' . $secret . '.jpg', $create, $chmod);
}
function getSquareFile($id, $secret, $create = null, $chmod = null)
{
return new File(WWW_ROOT . 'photos' . DS . 'square' . DS . $id . '-' . $secret . '.jpg', $create, $chmod);
}
function getBannerFile($id, $secret, $create = null, $chmod = null)
{
return new File(WWW_ROOT . 'photos' . DS . 'banner' . DS . $id . '-' . $secret . '.jpg', $create, $chmod);
}
function getBuddyFile($id, $secret, $create = null, $chmod = null)
{
return new File(WWW_ROOT . 'photos' . DS . 'buddy' . DS . $id . '-' . $secret . '.jpg', $create, $chmod);
}
function beforeDelete()
{
$this->loadModels('PhotoComment', 'PhotoTag', 'PhotoFavorite', 'PhotoLike', 'PhotoDislike', 'Notification');
$photo = $this->findById($this->id());
$this->secret = $photo['Photo']['secret'];
foreach(array($this->getOriginalFile($this->id(), $this->secret), $this->getLargeFile($this->id(), $this->secret), $this->getMediumFile($this->id(), $this->secret), $this->getSmallFile($this->id(), $this->secret), $this->getThumbFile($this->id(), $this->secret), $this->getSquareFile($this->id(), $this->secret), $this->getBannerFile($this->id(), $this->secret), $this->getBuddyFile($this->id(), $this->secret)) as $file)
{
if($file->exists())
$file->delete();
}
return true;
}
function afterDelete()
{
}
}
?>
I hope it helps,... enjoy it,...
On Saturday, March 30, 2013 6:16:12 PM UTC-7, Robert Gravel wrote:
Hi All,
I am trying to use the cake_gallery plugin https://github.com/vitorpc/cake_gallery for cake 1.3 but for some reason the thumbnail is not generated. Seems some issue with photo.php model??
In firebug i get some errors.
<b>Warning</b> (2)</a>: imagecreatetruecolor() [<a href='http://php.net/function.
imagecreatetruecolor '>
function.imagecreatetruecolor< /a>]:
Invalid image dimensions [<b>APP\plugins\cake_gallery\models\photo .php</b>, line <b>104</b>]
I have GD on my server. same errors on my server as my xampp server.
Anyone have any luck with this or can recommend a gallery plugin with upload and thumb creation
Thank you
Robert
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment