1. Go to this page and download the library: Download coercive/fileupload 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/ */
coercive / fileupload example snippets
use Coercive\Utility\FileUpload;
# EXAMPLE IMAGE FILE
$oImageUpload = new ImageUpload([
ImageUpload::OPTIONS_NAME => 'img_file',
ImageUpload::OPTIONS_ALLOWED_EXTENSIONS => ['jpeg', 'jpg', 'gif', 'png']
]);
# ERRORS
if($oImageUpload->getErrors()) { exit; }
# SAVE : add extension auto
$oImageUpload->save('/example/path/' . $sImgName_auto_extension);
if($oImageUpload->getErrors()) { exit; }
# Where is my file ?
$sMyFile = $oImageUpload->getDestPath();
use Coercive\Utility\FileUpload;
# EXAMPLE FILE
$oFileUpload = new FileUpload([
FileUpload::OPTIONS_NAME => 'file',
FileUpload::OPTIONS_ALLOWED_EXTENSIONS => ['pdf']
]);
# ERRORS
if($oFileUpload->getErrors()) { exit; }
# SAVE
$oFileUpload->save('/example/path/' . $sFileName . '.pdf');
if($oFileUpload->getErrors()) { exit; }
# EXAMPLE MOD
$oFileUpload = new FileUpload([
FileUpload::OPTIONS_NAME => 'file',
FileUpload::OPTIONS_CHMOD_DIR => 0777, # IF DIRECTORY NOT EXIST
FileUpload::OPTIONS_CHMOD_FILE => 0777 # WHEN USE MOVE OR COPY
]);
# YOU CAN USE INTERNAL HELPER
$oFileUpload = new FileUpload([
[ ... ]
FileUpload::OPTIONS_CHMOD_DIR => FileUpload::CHMOD_OWNER_WRITE,
FileUpload::OPTIONS_CHMOD_FILE => FileUpload::CHMOD_OWNER_READ,
[ ... ]
]);
FileUpload::CHMOD_FULL; # 0777
FileUpload::CHMOD_OWNER_FULL; # 0700
FileUpload::CHMOD_OWNER_READ; # 0400
FileUpload::CHMOD_OWNER_WRITE; # 0200
FileUpload::CHMOD_OWNER_EXEC; # 0100
FileUpload::CHMOD_OWNER_FULL_GROUP_READ_EXEC; # 0750
FileUpload::CHMOD_OWNER_FULL_GROUP_READ_EXEC_GLOBAL_READ; # 0754
FileUpload::CHMOD_OWNER_FULL_GROUP_READ_EXEC_GLOBAL_READ_EXEC; # 0755
FileUpload::CHMOD_OWNER_READ_WRITE; # 0600
FileUpload::CHMOD_OWNER_READ_WRITE_GROUP_READ; # 0640
FileUpload::CHMOD_OWNER_READ_WRITE_GROUP_READ_GLOBAL_READ; # 0644
use Coercive\Utility\FileUpload;
# Need Something ?
$oFileUpload
->getDestPath();
...
->getFilePathInfo();
...
->getMaxFileSize();
...
->getFileSize();
...
->getFileError();
...
->getFileType();
...
->getFilePath();
...
->getFileExtension();
...
->getFileName();
...
->getErrors();
...
->getChmodDir();
...
->getChmodFile();
# You can delete temp file by using :
$oFileUpload
->deleteTempFile();