In case you've missed it, you are looking at an older version of the website. Checkout our latest version, we promise you will love it 😍

callback_before_upload

void callback_before_upload( mixed $callback )
Quick Description: A callback that triggered before the upload functionality. This callback is suggested for validation checks.
Available for version >= 1.2

A callback that triggered before the upload functionality. This callback is suggested for validation checks.

If you return a string then it will alert the message of the string before the upload. So the upload will not work and the message will be alerted to the end-user. If you return a simple false then the default message of the upload error will appear, without of course uploading the file. If you return true, the upload will continue as normal.

You can see a full example of callback_before_upload below:

 
<?php
 
function employees_management()
{
    $crud = new grocery_CRUD();
 
 
    $crud->set_table('employees');
    $crud->set_relation('officeCode','offices','city');
    $crud->display_as('officeCode','Office City');
    $crud->set_subject('Employee');
 
    $crud->set_field_upload('file_url','assets/uploads/files');
    $crud->callback_before_upload(array($this,'example_callback_before_upload'));
 
    $output = $crud->render();
 
    $this->_example_output($output);
}    
 
 
function example_callback_before_upload($files_to_upload,$field_info)
{
/*
 * Examples of what the $files_to_upload and $field_info will be:    
$files_to_upload = Array
(
        [sd1e6fec1] => Array
        (
                [name] => 86.jpg
                [type] => image/jpeg
                [tmp_name] => C:\wamp\tmp\phpFC42.tmp
                [error] => 0
                [size] => 258177
        )
 
)
 
$field_info = stdClass Object
(
        [field_name] => file_url
        [upload_path] => assets/uploads/files
        [encrypted_field_name] => sd1e6fec1
)
 
*/
 
 
    if(is_dir($field_info->upload_path))
    {
        return true;
    }
    else
    {
        return 'I am sorry but it seems that the folder that you are trying to upload doesn\'t exist.';    
    }
 
}