PHP code example of muhammadsiyab / file_upload

1. Go to this page and download the library: Download muhammadsiyab/file_upload library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

muhammadsiyab / file_upload example snippets


     
 


// Array containing custom messages 
// (Optional parameter, if not passed, default error messages will be used)

$custom_messages = [
    'types' => 'The file type is not allowed',
    'max_size' => 'The file size must not be greater than :size kb'
];


if ( isset($_POST['submit']) ) {
    
    // Instantiate `Upload` Class
    $upload = new FileUpload\Upload('field_name', [
        'upload_dir' =>   'uploads/',
        'max_size'   =>   100,
        'types'      =>   'png|jpg|jpeg',
    ], $custom_messages);


    // Check whether the uploading is done or not 
    if ( $upload->is_uploaded() == TRUE ) {
        // File uploaded successfully
        echo 'File uploaded';
    } else {
        // Display errors
        echo $upload->display_errors();
    }
}
 php
if ( $upload->is_uploaded() == TRUE ) {
    // File upload success
} else {
    // File upload failure
}
 php
echo display_errors();
 php
echo formatted_errors('<div class="errors">', "</div>");
 php
echo bootstrap_errors();