2014-02-20 86 views
-2

我在POST中獲得圖像,我的想法是禁用此功能中的安全性。在功能中禁用安全

可能嗎?任何想法?

public function admin_addImage($id = null){ 
    $this->Hotel->id = $id; 
    if (!$this->Hotel->exists()) 
     throw new NotFoundException(__('Invalid Hotel')); 
    $image = $_FILES['uploadImage']; 
    ClassRegistry::init('HotelImage')->create(); 
    if ($image['name']) { 
     $imageName = md5(Security::generateAuthKey()); 
     $result = $this->uploadFiles('files/hotels/images', array($image), $imageName, null, 'I',array('width' => 300, 'height' => 300)); 
     if (!empty($result['errors'][0])) { 
      $this->Session->setError(__('Invalid file format')); 
      $this->redirect($this->referer()); 
      } 
     if($result['urls'][0]){ 
      ClassRegistry::init('HotelImage')->save(array('hotel_id'=>$id)); 
      ClassRegistry::init('HotelImage')->saveField('image', md5($imageName).'.'.basicsLix::getExtension($image['name'])); 
     } 
    } 
$this->redirect($this->referer()); 
} 

解決方案:

if(isset($this->Security) && $this->RequestHandler->isPost() && $this->action == 'admin_addImage'){ 
      $this->Security->validatePost = false; 
      $this->Security->enabled = false; 
      $this->Security->csrfCheck = false; 
    } 
+0

禁用哪些安全措施? –

+0

此安全性:public $ components = array('Security','Acl','RequestHandler') – Hernandez91

+0

爲什麼你需要/想要禁用它? – burzum

回答