I'm uploading photos in webroot/photos ... and its working,... the only
thing is it need to add to a database after upload, which is not doing,...
here is whole function:
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'])))
{
header('HTTP/1.1 401 Unauthorized');
exit('You reached your upload limit');
}
else
{
$fileParts = pathinfo($_FILES['Filedata']['name']);
$secret = $this->generateRandomString(20);
$name = str_replace(array('.jpg', '.jpeg', '.JPG', '.JPEG', '.png',
'.PNG'), '', $fileParts);
$tempFile = $_FILES['Filedata']['tmp_name'];
$original_file = $this->Photo->getOriginalFile($this->Photo->id,
$secret, true);
$original_file_path = $original_file->pwd();
$targetFile = $original_file_path;
move_uploaded_file($tempFile, $targetFile);
exec('/usr/bin/convert -geometry 768x640 ' . $targetFile . ' ' .
$this->Photo->getLargeFile($this->Photo->id, $secret)->pwd() .' > /dev/null
2>&1 &');
exec('/usr/bin/convert -geometry 400x360 ' . $targetFile . ' ' .
$this->Photo->getMediumFile($this->Photo->id, $secret)->pwd() .' >
/dev/null 2>&1 &');
exec('/usr/bin/convert -geometry 135x135 ' . $targetFile . ' ' .
$this->Photo->getSmallFile($this->Photo->id, $secret)->pwd() .' > /dev/null
2>&1 &');
exec('/usr/bin/convert -geometry 140x220 ' . $targetFile . ' ' .
$this->Photo->getThumbFile($this->Photo->id, $secret)->pwd() .' > /dev/null
2>&1 &');
exec('/usr/bin/convert -thumbnail x480 -resize "480x<" -resize 50%
-gravity center -crop 240x240+0+0 +repage ' . $targetFile . ' ' .
$this->Photo->getBannerFile($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 ' . $targetFile . ' ' .
$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 ' . $targetFile . ' ' .
$this->Photo->getBuddyFile($this->Photo->id, $secret)->pwd() .' > /dev/null
2>&1 &');
$this->Photo->create();
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']);
}
$this->Session->setFlash(__('The photos are saved.', true));
}
}
On Friday, October 5, 2012 2:51:39 PM UTC-7, ivnrmc wrote:
>
> what are your error? this code is on very big mess. I don't know what are
> you trying to do, but you should clean and simplify all of this.
>
> 2012/10/5 Chris <[email protected] <javascript:>>
>
>> hi guys,...
>> I can't save data in database,... I'm on cake 1.3 what am I doing
>> wrong...? can anyone help please,....?
>> thanks in advance
>>
>>
>> $this->Photo->create();
>> 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']);
>> }
>>
>> --
>> Like Us on FacekBook 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 post to this group, send email to [email protected]<javascript:>
>> .
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>.
>> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>>
>>
>>
>
>
>
> --
> *Ivan Rimac***
> mail: [email protected] <javascript:>
> *tel: +385 95 555 99 66*
> *http://ivanrimac.com*
>
>
--
Like Us on FacekBook 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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.