Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7874029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:41:21+00:00 2026-06-03T02:41:21+00:00

Hi I’ve created a file upload form, it all works perfectly apart from when

  • 0

Hi I’ve created a file upload form, it all works perfectly apart from when I press submit it does not re-direct me to the Uploads/add.ctp, but it does save the file to the directory and on to the database.In fact if I point the re-direct to uploads/browse it still does not take me to uploads/browse.

This is my controller

public function add() {

if(!empty($this->data)){

    $file = $this->request->data['Upload']['file'];
if ($file['error'] === UPLOAD_ERR_OK && $this->Upload->save($this->data)){
    $this->Upload->save($this->data);
    if(move_uploaded_file($file['tmp_name'],APP.'webroot/files/uploads'.DS.$this->Upload->id.'.mp4')) {
    $this->Session->setFlash(__('<p class="uploadflash">The upload has been saved</p>', true));
    $this->redirect(array('controller'=>'Uploads','action' => 'add'));
    } else{

    $this->Session->setFlash(__('<p class="uploadflash">The upload could not be saved. Please, try again.</p>', true));

    }
} 


}
}

and this is my form

      <div class="maincontent">
      <?php echo $this->Form->create('Upload', array('type' => 'file', 'class'=>'uploadfrm'));?>
<fieldset class='registerf'>
    <legend class='registerf2'>Upload a Video</legend>
<?php
    echo 'Upload your video content here, there is no size limit however it is       <b>.mp4</b> file format only.';
    echo '<br/>';
    echo '<br/>';
    echo $this->Form->input('name', array('between'=>'<br />', 'class'=>'input'));
    echo $this->Form->input('eventname', array('between'=>'<br />'));
    echo $this->Form->input('description', array('between'=>'<br />', 'rows'=> '7', 'cols'=> '60'));
    echo  $this->Form->hidden('userid', array('id' => 'user_id','value' => $auth['id']));
    echo $this->Form->hidden('username', array('id' => 'username', 'value' => $auth['username']));
    echo $this->Form->input('file', array('type' => 'file'));
    echo "<br/>"
?>
<?php echo $this->Form->end(__('Submit', true));?>
</fieldset>

     <?php

   class UploadsController extends AppController {
   public $name = 'Uploads';

      public $helpers = array('Js');



// Users memeber area, is User logged in…
 public $components = array(
    'Session',
    'RequestHandler',
    'Auth'=>array(
        'loginRedirect'=>array('controller'=>'uploads', 'action'=>'browse'),
        'logoutRedirect'=>array('controller'=>'users', 'action'=>'login'),
        'authError'=>"Members Area Only, Please Login…",
        'authorize'=>array('Controller')
    )
  );


       public function isAuthorized($user) {
            // regular user can access the file uploads area
        if (isset($user['role']) && $user['role'] === 'regular') {
            return true;
             }

             // Default deny
                return false;
            }





function index() {
        $this->set('users', $this->Upload->find('all'));

}




// Handling File Upload Function and updating uploads database


    public function add() {

        if(!empty($this->data)){

            $file = $this->request->data['Upload']['file'];
            if ($file['error'] === UPLOAD_ERR_OK){
            $this->Upload->save($this->data); 
                if(move_uploaded_file($file['tmp_name'],APP.'webroot/files/uploads'.DS.$this->Upload->id.'.mp4')) 
                {
                    $this->redirect(array('controller' => 'Uploads', 'action' => 'add'));
                    $this->Session->setFlash(__('<p class="uploadflash">The upload has been saved</p>', true));


                    }   }else {

                        $this->Session->setFlash(__('<p class="uploadflash">The upload could not be saved. Please, try again.</p>', true));

                            }

                }
                }   

function browse () {
        // Find all in uploads database and paginates
$this->paginate = array(
    'limit' => 5    ,
    'order' => array(
        'name' => 'asc'
    )
    );
    $data = $this->paginate('Upload');
    $this->set(compact('data'));


     }

function recentuploads () {
$uploads =  $this->Upload->find('all', 
    array('limit' =>7,
    'order' => 
        array('Upload.date_uploaded' => 'desc')));
    if(isset($this->params['requested'])) { 
         return $uploads; 
         } 
            $this->set('uploads', $uploads); 
}

function watch ($id = null){
$this->set('isAjax', $this->RequestHandler->isAjax());

    // Read Uploads Table to watch video
    $this->Upload->id = $id;      
    $this->set('uploads', $this->Upload->read());



    // Load Posts Model for comments related to video
            $this->loadModel('Post');
    $this->paginate = array(
                'conditions' => array(
                'uploadid' => $id),
                'limit' => 4
                );

    $data = $this->paginate('Post');
    $this->set(compact('data'));






// Load Likes Model and retrive number of likes and dislikes

    $this->loadModel('Like');

    $related_likes = $this->Like->find('count', array(
        'conditions' => array('uploadid' => $id)
    ));
    $this->set('likes', $related_likes);
    }




}
    ?>

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:41:22+00:00Added an answer on June 3, 2026 at 2:41 am

    If I add the following line in the function add

                $this->render();
    

    everything works perfectly, I’m struggling for the life of me to work out why I have to render the view if surely all other views are rendered by default.
    But anyway got it working!
    Hope this helps others 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.