Download the PHP package samsonphp/upload without Composer
On this page you can find all versions of the php package samsonphp/upload. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package upload
SamsonPHP Upload module
Connection
To use this module in your project you must add dependency in your :
After doing or you will get all classes and functions of Upload module.
Configuration
Configuration for Upload module is not necessary, but you can use it if you want to create unique file name or upload dir name for uploading files.
If you will not use configuration, your upload catalog will be called 'upload' and file name will be random generated.
Thanks to SamsonPHP module/service configuration you can create simple config class:
Create async file uploading
The main feature of current module is asynchronous file uploading. Look at the example.
Example of HTML code
First of all you need to create html container with your file input:
- Input with class "action" defines handler of your uploading. It can be controller method in your bundle or simple controller function. It always must have class "action".
- Input with class "__file_size" defines max size of uploading file. It always must have class "__file_size".
- Input with class "__example_upload" is input button for choosing file from clients computer. If you are using class name "__upload" for this input, you don't need to create some javascript code in order for everything to work.
Also you can add following feature blocks :
- Container with class "__progress_text" will show you percents of file uploading.
- Paragraph tag inside container with class "__progress_bar" will create animation as progress bar of uploading.
Remember, that you must add some css styles for this blocks to use them as you want.
Example of javascript code
If you are using input with class different from "__upload", you need to handle you inputs:
The second parameter in function is not necessary, you can use it for creating something special while file is uploading.
Example of uploading handler
Server action in our HTML example is controller 'catalog/upload'. Let's create this function:
To create file upload you need to create class \samsonphp\upload\Upload, constructor of which can have three parameters.
- First parameter is array of allowable file extensions for uploading file.
- Second is array of parameters (or just one parameter) for your callback functions. It can be used if you are using module configuration.
- The third one is configuration class. This is system parameter which default value is m('upload'). Better do not specify it, if you are working with simple upload module.
Method that directly create uploading called . You can get main file information using parameters of this method.
Also we can create our callback functions that are defined in configuration class:
As you see, we have parameter in our name handler function. This parameter is always defined as last parameter of this callback function.
In our case after created callback functions, upload catalog will be called 'upload/catalog5' and file name will be like 'item5'.
Don't forget, that in current example all uploading files will have simple name (maybe different extensions), so you must come up with some logic for using upload file name handler correctly.
Developed by SamsonOS.