I have recently battled with the same problem as you OmarC I can explain whats happening to you but unfortunately there is no real solution.
The two major php.ini settings which can be explained for uploads are as follows: post_max_size - sets max size of post data allowed. (We will work on 8M default) upload_max_filesize - contains the maximum size of a file which can be uploaded via a form. (We will work on 2M default); The post_max_size is generally higher than the upload_max_filesize as the post_max_size must encompass all the other form inputs as well as the file to upload. This being said please follow on below. Firstly the code in the controller can execute but you cant do a check on $this->data in the scenario you propose cause the $_POST and $_FILES globals will be emtpy. Consider these four scenarios Scenario 1 The user does not upload anything then cakes validation fires on your other form inputs and you are a happy man. In this scenario the $this- >data array contains info and the $_POST and $_FILES contain information as well. In this Scenario the post_max_size is never reached so the global variables $_POST and $_FILES exist and errors can be captured. UPLOAD_ERR_OK is set (Value: 0; There is no error, the file uploaded with success). Scenario 2 The user uploads a file size less than 2M in which case the upload_max_filesize validates, the post_max_size is never reached, cakes validation fires on the rest of your data and again you are a happy man. Again the $_POST and $_FILES is set. UPLOAD_ERR_OK is set (Value: 0; There is no error, the file uploaded with success). Scenario 3 The user uploads a file size greater than the upload_max_filesize BUT less than the post_max_size. Again the $_POST and $_FILES are set and the error can be captured UPLOAD_ERR_INI_SIZE (Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.) Scenario 4 (the one you are experiencing) The user uploads a file which is greater than the post_max_size (in this example is 8M), now here is where the headache begins, because the file being uploaded exceeds the post_max_size the $_POST and $_FILES globals ARE NOT SET AT ALL. This means that all the data which was submitted from your form is empty, this means that because cakes functions generally checks for if(!empty($this->data)) it loads the page as if the user just requested the url. Solution The only solution i can offer you is how to catch the error if a user exceeds the post_max_size. //uploads_controller.php function add() { if($this->referer() == '/uploads/uploadFile'){ $this->set('msg', 'please choose a file smaller than.'.ini_get ('upload_max_filesize')); } } function uploadFile(){ if (!empty($this->data)) { if($this->data['Upload']['source']['error'] == UPLOAD_ERR_OK){ $this->Session->setFlash(__('Work your magic', true)); }else{ $errorMsg = $this->fileUploadErrorMessage($this->data['Upload'] ['source']['error']); $this->Session->setFlash(__('Error: '.$errorMsg)); } }else{ if(!is_uploaded_file($this->data['Upload']['source']['tmp_name']) && ($this->referer() == '/uploads/add')){ $this->Session->setFlash(__('Form data greater than php.ini allows', true)); $this->redirect('add'); } } } //views/uploads/add.ctp <div class="uploads form"> <?php echo $form->create('Upload', array('type' => 'file', 'action' => ('uploadFile')));?> <fieldset> <legend><?php __('Add Upload');?></legend> <?php echo $form->input('source', array('type' => 'file')); echo $form->input('dummy'); ?> </fieldset> <?php echo $form->end('Submit');?> </div> Hope this helps ya. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---