Upload Library



( ZN >= 0.0.1 )

The class that performs the file upload function. It also allows you to load multiple files, as well as get information about file operations or errors that occur in the process.

 

 

# Applications


# Multiple File Upload with Jquery & Ajax & SweetAlert
# File Upload with DropzoneJS 

 

 

# INI Configuration


The upload settings in the following path are used to set the ini settings for file upload .

File: Settings / Ini.php
Array $ settings = [] php.ini Session settings list.
File:  Settings / Htaccess.php
Bool $ status = false Specifies whether the settings in the Settings section are saved in the .htaccess file. TRUE the settings are saved in the .htaccess file. FALSE it only  tries  to configure it via php_ini .

 

 

# Methods


this extensions ( String ... $ args )
this mimes ( String ... $ args )
this Game Converter ( Boolean $ converter = true )
this encode ( String $ hash = 'md5' )
this encodeLength ( Int $ encodeLength = 8 )
this prefix ( String $ prefix )
this maxsize ( Int $ maxsize = 0 )
this source ( String $ source = 'upload' )
this target ( String $ target = UPLOADS_DIR )
this settings ( Array $ set = [] )
Bool start ( String $ fileName = 'upload' , String $ rootDir = UPLOADS_DIR )
Mixed info ( String $ info = NULL )
Mixed error ( Void )

 

 

# Extensions ( ZN> = 3.0.0 )


Used to specify which extensions can be uploaded.

Parameters

String ... $ extensions Downloadable file extension types.
return this

Use of

Upload::extensions('jpg', 'png', 'gif', 'txt')->start('file');

 

 

# Mimes ( ZN >= 5.4.1 )


File extensions do not provide information about the actual identity of that file. For this reason, you need to limit which types of files to load. With this method, you can decide which mime types can be loaded.

( ZN FE 5.5.80 )

In this update, a bug that caused mime control to fail correctly was fixed.

Parameters

String $ Mimes ... Downloadable file content data types.
return this

Use of

Upload::mimes('image/jpeg', 'image/png')->start('file');

 

 

# ConvertName ( ZN> = 3.0.9 )


Foreign or special characters in filenames are converted to slug type.

( ZN FE 5.5.9 )

As of this version, the string is accepted as a parameter in the string . You will now be able to use your own naming conventions.

Parameters

Bool $ convert = true Are the filename translated to slug ?. If parameter is not specified, it is accepted as true and dialing is done.
return this

Use of

Upload::mimes('image/jpeg', 'image/png')
      ->convertName()
      ->start('file');

 

 

# Encode ( ZN >= 3.0.9 )


Adds an encrypted prefix to the uploaded file.

( ZN FE 5.5.80 )

An arrangement was made to disable the prefix()method of using this update method encode()

Parameters

String $ hash = 'md5' Specifies the algorithm to which the prefix will be encoded.
return this

Use of

Upload::mimes('image/jpeg', 'image/png')
      ->encode('sha1')
      ->start('file');

 

 

# EncodeLength ( ZN >= 3.0.9 )


Used to set the length of the encrypted prefix.

Parameters

Int $ length = 8 It is specified how many characters the encrypted prefix will be.
return this

Use of

Upload::mimes('image/jpeg', 'image/png')
      ->encode('sha1')
      ->encodeLength(10)
      ->start('file');

 

 

# Prefix ( ZN >= 3.0.9 )


Used to append a prefix to your uploaded file. If you would like to have your prefix addedEncode () You need to set the parameter of the method to false.

( ZN FE 5.5.80 )

In this update, the requirement of the encode () method to be false has been removed. 

Parameters

String $ prefix Prefix.
return this

Use of

Upload::mimes('image/jpeg', 'image/png')
      ->encode(false)
      ->prefix(time())
      ->start('file');

 

 

# Maxsize ( ZN >= 3.0.9 )


Used to specify the maximum size of the uploaded file in bytes .

( ZN FE 5.5.9 )

As of this version, the string is accepted as a parameter in the string . Instead of sending the amount of bytes directly 20MB, you will be able to use it 5KBas string data.

Parameters

Int $ maxsize = 0 The maximum size of the uploaded file. The size is expressed in bytes.
return this

Use of

Upload::mimes('image/jpeg', 'image/png')
      ->maxsize(1024 * 1024 * 20) // 20 MB
      ->start('file');

 

 

# Source ( ZN >= 3.0.9 )


start()It behaves the same as parameter 1 of the method . Represents the name value of the input file form object. That is, from which source the file is downloaded.

Parameters

String $ name = 'upload' The name value of the Form :: file () object.
return this

Use of

Upload::mimes('image/jpeg', 'image/png')
      ->maxsize(1024 * 1024 * 20) // 20 MB
      ->source('file')
      ->start();

 

 

# Target ( ZN >= 3.0.9 )


start()It performs the same function as the 2nd parameter of the method . Where to load the file. The directory to which the files will be pre-loaded is each project's own Resources / Uploads / directory

Parameters

String $ target = UPLOADS_DIR The directory where the files will be installed.
return this

Use of

Upload::mimes('image/jpeg', 'image/png')
      ->maxsize(1024 * 1024 * 20) // 20 MB
      ->source('file')
      ->target(FILES_DIR . 'my_uploads/')
      ->start();

Or;

Upload::mimes('image/jpeg', 'image/png')
      ->maxsize(1024 * 1024 * 20) // 20 MB
      ->start('file', FILES_DIR . 'my_uploads/');

.

 

 

# Settings ( ZN> = 0.0.1 )


Above is used to make the settings made by the optional methods as an array.

Parameters

Array $ settings It is for configuring file upload settings.
String $ extensions It is used to determine which extensions are to be loaded. Extensions are specified using a hyphen (|) .
String $ mimes Used to determine which file types to install. Extensions are specified using a hyphen (|) .
String $ encode = 'md5' It şifreli ön ekspecifies which encryption algorithm to use to be added to the file to be loaded .
Int $ encodeLength = 8 The password length is specified.
String $ prefix The file to be loaded is used to insert a prefix.
Int $ MaxSize Used to determine the maximum size in bytes of the uploaded file.
Bool $ convertName = true Do you convert foreign characters? This use is to avoid the loading problem arising from the intended foreign characters.
return this

uses

Upload::settings
([
    'encode'     => false,
    'prefix'     => '__prefix__',
    'extensions' => 'jpg|png|gif',
    'maxsize'    => 8096
]);

It can be used in the optional method for each setting above.

 

 

# Start ( ZN >= 0.0.1 )


Starts the file upload process.

Parameters

String $ Fileınputn Game The name of the form input file object.
String $ target = UPLOADS_DIR The directory where the files will be installed.
return this

uses

Upload::settings
([
    'encode'     => false,
    'prefix'     => '__prefix__',
    'extensions' => 'jpg|png|gif',
    'maxsize'    => 8096
])->start('upload');

Configuration with Optional Methods

If you want to do the above operation with optional options;

Upload::encode(false)
      ->prefix('__prefix__')
      ->extensions('jpg', 'png', 'gif')
      ->maxsize(8*96)
      ->target('DirrentUploadDir')
      ->start('upload');

The upload used in the start ( 'upload' ) method above is the value of the object that is the subject of the upload operation .<form input="file" name="upload">name

 

 

# Info ( ZN >= 1.0.3 )


Used to get information about the file during file operations. Returns the data in the object data type. If a single piece of information is used, the information name can be written as a parameter.

Parameters

String $ infoName = NULL Which information is requested.
name File name.
type File type.
to you File size.
tmpn Game The name in the file temp directory.
error Error number.    
path The path the file was uploaded to.
Encode Game The encrypted name of the file.
return Mixed

uses

File: Views / UploadExample / main.php
<?php
echo Form::enctype('multipart')->open('form');
echo Form::file('uploadFile');
echo Form::submit('uploadButton');
echo Form::close();
File: Controllers / UploadExample.php
Upload::settings
([
    'encode'     => false,
    'prefix'     => '__prefix__',
    'extensions' => 'jpg|png|gif',
    'maxsize'    => 8096
])->start('uploadFile');

output( Upload::info() );
name        => string 'logosmall.png' (length = 18 ) ,
type        => string 'image / png' (length = 11 ) ,
you        => integer 129 296 (length = 6 ) ,
tmpn Game     => string 'xampp7 / tmp / php26E9.tmp ' (length = 27 ) ,
error       => integer 0 (length = 1 ) ,
path        => string 'xampp7 / htdocs / zeroneed / Projects / Frontend / Resources / uploads / __ prefix__logosmall.png' (length = 86 ) ,
encode up => string '__prefix__logosmall.png' (length = 24 )

 

 

# Error ( ZN >= 0.0.1 )


It tells you whether any errors have occurred after the installation.

Parameters

void
return Mixed

uses

output( Upload::error() );

 

 

# Multiple File Upload with Jquery & Ajax & SweetAlert


Follow the steps below to upload a file using jquery with ajax.

Include Jquery Form Script

Where your JavaScript tags are located on your system, add the following command to it. This place is usually  [head] [/head]between the labels.

File: Views / sections / head.wizard.php
@Import::style('bootstrap', 'sweetAlert')
@Import::script('jquery', 'sweetAlert')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.min.js"></script>
Prepare the Fomu

Do enctypenot forget to edit the value of the form element for the file upload .

File: Views / Home / main.wizard.php
@Form::id('uploadForm')->enctype('multipart')->open()
@Form::file('upload', true)
@Form::submit('uploadButton', 'Do Upload')
@Form::close()
Prepare JS Codes

We create our ajax codes to send the form values ​​to the corresponding controller.

File: Views / sections / footer.wizard.php
<script>
$('#uploadForm').ajaxForm
({
    url: 'URL::site('Home/upload')',
    type: 'post',
    dataType: 'json',
    success: function(data)
    {
        if( data.success !== undefined )
        {
            swal("Başarılı.", data.success, "success");
        }
        else
        {
            swal("Hatalı!", data.error, "error");
        }
    }
});
</script>
Prepare the Controller

The following usage can be expanded according to your goals.

File: Controllers / Home.php
public function upload()
{
    if( ! \Http::isAjax() )
    {
        return false;
    }

    \Upload::start('upload');

    if( $error = \Upload::error() )
    {
        $data['error'] = $error;
    }
    else
    {
        $data['success'] = 'Dosya başarı ile yüklendi!';
    }

    echo json_encode($data);
}

 

 

# File Upload with DropzoneJS 


Click for detailed usage of DropzoneJS . Follow the steps below to upload files with Dropzone.

Include Dropzone Script

You can include the remote link of the Import library with DropzoneJS. Where your JavaScript tags are located on your system, add the following command to it. This place is usually  [head] [/head]between the labels.

File: Views / sections / head.wizard.php
@Import::style('dropzone'):
@Import::script('dropzone'):
Prepare the Form

Do enctypenot forget to edit the value of the form element for the file upload .

File: Views / Home / main.wizard.php
@Form::action('Home/upload')->enctype('multipart')->class('dropzone')->open('form'):
<div class="fallback" id="fallback">
@Form::file('file', true):
</div>
@Form::close():
Prepare JS Codes

2. parametresiIncludes extra settings for the Dropzone object . For the use of this parameterdropzonejs see the user manual.

File: Views / sections / footer.wizard.php
<script>
var dropzone = new Dropzone("#fallback");
</script>
Prepare the Controller

The following usage can be expanded according to your goals.

File: Controllers / Home.php
public function upload()
{
    if( ! Http::isAjax() )
    {
        return false;
    }

    Upload::mimes('image/jpeg', 'image/png')
          ->prefix(time())
          ->start('file');
}