The request has been black-holed

2019-09-02 07:55发布

问题:

when i am upload multiple images i found The request has been black-holed Error: The requested address '/admins/uploadimage1' was not found on this server.

my contoller function

public function uploadimage1()
{
    if($this->request->is('post'))
    {
    $a=$this->data['Admins']['imgs'];
    print_r($a);
}
}

view file

<?php echo $this->Form->create('Admins',array('controller'=>'Admins','action'=>'uploadimage1', 'type'=>'file', 'accept-charset'=>'utf-8'));?>
        <table width="95%">
            <tr><td><b>Image Title</b></td><td><?php echo $this->Form->input('title', array('type' => 'text', 'class'=>'input-block-level','placeholder'=>'Image Title' ,'label'=>false )); ?></td></tr>
            <tr><td></td><td>

            <?php echo $this->Form->input('imgs.',array('type'=>'file', 'label'=>false, 'multiple')); ?></td></tr>
            <tr><td></td><td><?php echo $this->Html->image('../img/adminimages/upload.jpg', array('id'=>'blah','height'=>'100px','width'=>'100px')); ?></td></tr>
          <tr><td></td><td>
          <?php 
            foreach ($Retailers as $Retailer)
            {
                $r_id=$Retailer['Retailer']['id'];
            echo $this->Form->input('r_id', array('type'=>'hidden','value'=>$r_id)); }?>
              <?php echo $this->Form->submit('Submit',array('class' => 'button')); ?></td></tr></table>

            <?php echo $this->Form->end();

my controller

<?php


App::uses('AppController', 'Controller');


class AdminsController extends AppController 
{


    public $name='Storelocators/Admins';

/**
 * This controller does not use a model
 *
 * @var array
 */
    public $uses = array('Admin','Retailer','Gallery');

    public function beforeFilter() {

        $this->Security->unlockActions = ('uploadimage1');
        $this->Auth->allow('login','logout','signup','abhi');
    }

    public function beforeRender() {
        parent::beforeRender();
    }

    public function index() 
    {
        $this->layout='admin';

    }

    public function signup()
    {
            $this->layout='admin';          
                    if($this->request->is('post'))
        {

                    $admin_data=array (
                    'username'=>$this->data['Admins']['username'],
                    'email'=>$this->data['Admins']['email'],
                     'type'=>'Admin',
                    'password'=>$this->Auth->password($this->data['Admins']['password']));

                    $this->Admin->save($admin_data);
                        $this->Session->setFlash(__('Your are successfully Sign up.', true), 'default', array('class' => 'sukses'));    



           $this->redirect($this->referer());
        }
    }


        public function login(){
        $this->layout='admin';
        if($this->request->is('post')){
                    if($this->Auth->login()){   
                    $name = $this->Auth->user('username');

                  $this->Session->write('a', $name);  

                $this->redirect($this->Auth->redirect());

                }

            else{
                $this->Session->setFlash(__("Your email/password combination was incorrect.", true));
                $this->redirect($this->referer());


            }
        }
    }

    public function logout(){
        $this->Session->delete('a');
        $this->layout = false;
        $this->autoRender = false;  
        $this->Session->setFlash(__('You have logout successfully.', true), 'default', array('class' => 'message success'));
        $this->redirect($this->Auth->logout());
    }

    public function form()
    {
        $this->layout='admin';
        if($this->request->is('post'))
        {
            if(!empty($this->data['Admins']['imgs']['name']) && !empty($this->data['Admins']['imgs1']['name']) )
        {

        $file=$this->data['Admins']['imgs'];
        $file1=$this->data['Admins']['imgs1'];
        $ary_ext=array('jpg','jpeg','gif','png');
        $ext = substr(strtolower(strrchr($file['name'], '.')), 1);
    //  $ext1 = substr(strtolower(strrchr($file1['name'], '.')), 1); //get the extension


            if(in_array($ext,$ary_ext))
            {

               $date1=date('dmYhis');
                move_uploaded_file($file['tmp_name'], WWW_ROOT . 'img/adminimages/UploadImages/' .$date1.'_'.$file['name'] );
                move_uploaded_file($file1['tmp_name'], WWW_ROOT . 'img/adminimages/UploadImages/' .$date1.'_'.$file1['name'] );


              $n =  $this->request->data['Admins']['imgs'] = $file['name'];
               $n1 =  $this->request->data['Admins']['imgs1'] = $file1['name'];

               $date=date('d/m/Y');
               $days1=$this->data['Admins']['days'];
               $day=implode(",",$days1);

               $r_type1=$this->data['Admins']['r_type'];
               $r_types=implode(",",$r_type1);
               $my_data=array(
               'name'=>ucfirst($this->data['Admins']['name']),
               'address'=>ucfirst($this->data['Admins']['address']),
               'province'=>ucfirst($this->data['Admins']['province']),
               'region'=>ucfirst($this->data['Admins']['region']),
               'city'=>ucfirst($this->data['Admins']['city']),
               'nation'=>ucfirst($this->data['Admins']['nation']),
               'r_type'=>$r_types,
               'open_hours'=>$this->data['Admins']['hours1'].','.$this->data['Admins']['hours2'],
               'days'=>$day,
               'description'=>ucfirst($this->data['Admins']['description']),
               'logo_image'=>$date1.'_'.$n,
               'main_image'=>$date1.'_'.$n1,
               'status'=>'Active',
               'create_date'=>$date
               );

              $this->Retailer->save($my_data);
                        $this->Session->setFlash(__('Your Data Succefully Inserted.', true), 'default', array('class' => 'sukses'));    
                        $this->redirect(array('controller'=>'Admins','action'=>'uploadimage'));

            }

        }
        }
    }
    public function addname()
    {
        $this->layout='admin';

    }
    public function tabel()
    {
        $this->layout='admin';
        $this->set('Retailers' , $this->Retailer->find('all'));
    }
    public function uploadimage()
    {
        $this->layout='admin';
        $this->set('Retailers', $this->Retailer->find('all', array('order'=>array('Retailer.id DESC'),'limit'=>'1')));
        if($this->request->is('post'))
        {
            if(!empty($this->data['Admins']['imgs']['name']))
        {

        $file=$this->data['Admins']['imgs'];
        $ary_ext=array('jpg','jpeg','gif','png');
        $ext = substr(strtolower(strrchr($file['name'], '.')), 1);
    //  $ext1 = substr(strtolower(strrchr($file1['name'], '.')), 1); //get the extension


            if(in_array($ext,$ary_ext))
            {

               $date1=date('dmYhis');
                move_uploaded_file($file['tmp_name'], WWW_ROOT . 'img/adminimages/GalleryImages/' .$date1.'_'.$file['name'] );



             $date=date('d/m/Y');
              $n =  $this->request->data['Admins']['imgs'] = $file['name'];
              $gal_data=array(
              'r_id'=>$this->data['Admins']['r_id'],
              'image'=>$date1.'_'.$n,
              'title'=>ucfirst($this->data['Admins']['title']),
              'create_date'=>$date);

              $this->Gallery->save($gal_data);
              $this->Session->setFlash(__('Your Data Succefully Inserted.', true), 'default', array('class' => 'sukses'));  
                        $this->redirect($this->referer());
            }
        }
        }
    }

    public function addimage($id)
    {
        $this->layout='admin';
        $ir=$this->Retailer->findById($id);
        if($ir['Retailer']['status']=='Active')
        {
        $this->set('Gs',$this->Gallery->find('all', array('conditions'=>array('Gallery.r_id'=>$id))));
        //print_r($Gs);
        //print_r($Gallerys);
        //exit();
        if(!empty($id))
                {
                    if($this->request->is('post'))
                    {

                        if(!empty($this->data['Admins']['imgs']['name']))
        {

        $file=$this->data['Admins']['imgs'];
        $ary_ext=array('jpg','jpeg','gif','png');
        $ext = substr(strtolower(strrchr($file['name'], '.')), 1);
    //  $ext1 = substr(strtolower(strrchr($file1['name'], '.')), 1); //get the extension


            if(in_array($ext,$ary_ext))
            {

               $date1=date('dmYhis');
                move_uploaded_file($file['tmp_name'], WWW_ROOT . 'img/adminimages/GalleryImages/' .$date1.'_'.$file['name'] );



             $date=date('d/m/Y');
              $n =  $this->request->data['Admins']['imgs'] = $file['name'];
              $gal_data=array(
              'r_id'=>$id,
              'image'=>$date1.'_'.$n,
              'title'=>ucfirst($this->data['Admins']['title']),
              'create_date'=>$date);

              $this->Gallery->save($gal_data);
              $this->Session->setFlash(__('Your Data Succefully Inserted.', true), 'default', array('class' => 'sukses'));  
              $this->redirect($this->referer());
            }
        }
                    }
                }

        }
        else
        {
            $this->Session->setFlash(__('First Active this Retailer', true));
            $this->redirect($this->referer());
        }

    }
    public function uploadimage1()
    {
        if($this->request->is('post'))
        {
        $a=$this->data['Admins']['imgs'];
        print_r($a);
    }
    }
    public function updatestatus($id)
    {

            $urs=$this->Retailer->findById($id);
            if($urs['Retailer']['status']=='Active')
            {
                $this->Retailer->updateAll(array('Retailer.status' => '"De-Active"'), array('Retailer.id' => $id));
                $this->redirect(array('controller'=>'Admins', 'action'=>'tabel'));
            }
            else
            {
                $this->Retailer->updateAll(array('Retailer.status' => '"Active"'), array('Retailer.id' => $id));
                $this->redirect(array('controller'=>'Admins', 'action'=>'tabel'));
            }


        }



    public function gallery()
    {
        $this->layout='admin';
        //$this->set('Gs',$this->Gallery->find('all'));

        //$this->set('Gs',$this->Gallery->find('all', array('joins' => array(array('table' => 'retailers','alias' => 'Re','type' => 'inner','foreignKey' => true,'conditions'=> array('Re.id = Gallery.r_id'))))));
    $this->Set('Gs',$this->Gallery->find('all',array('fields'=> array('*','*'), 'joins'=> array( array('table'=>'retailers', 'type'=>'inner','conditions'=>array('Gallery.r_id=retailers.id','retailers.status'=>'Active'))))));

    //  print_r($Gs);
    //  $db =& ConnectionManager::getDataSource('default');
    //  $db->showLog();


//  exit();







    }



} ?>

This is my controller.

回答1:

Its not a issue on multiple upload. Its showing bcz of Security Component. You can bypass this by adding $this->Security->unlockActions = array('your actions');



回答2:

Add this code to your controller.....

public function beforeFilter(){
   $this->Security->unlockActions = array('action_name');
}


回答3:

You have to change the Security config.

Right:

$this->Security->config('unlockedActions', 'action_name');

Wrong:

$this->Security->unlockedActions = ['action_name'];