PHP code example of ikechukwukalu / clamavfileupload
1. Go to this page and download the library: Download ikechukwukalu/clamavfileupload 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/ */
ikechukwukalu / clamavfileupload example snippets
use Ikechukwukalu\Clamavfileupload\Facades\Services\FileUpload;
FileUpload::uploadFiles($request); //returns bool|FileUploadModel|EloquentCollection
/**
* Default settings
*
* 'name' => null // This is different from file name
* 'input' => config('clamavfileupload.input', 'file')
* 'folder' => null
* 'hashed' => config('clamavfileupload.hashed', false)
* 'visible' => config('clamavfileupload.visible', true)
* 'disk' => config('clamavfileupload.disk', 'local')
*
*
*/
/**
* You can also overwrite the default settings with custom settings
*/
$settings = [
'folder' => 'pdfs'
];
$fileUpload = new FileUpload;
$fileUpload::uploadFiles($request, $settings); //returns bool|FileUploadModel|EloquentCollection
/**
* Access last scan results
*/
$fileUpload::getScanData()
/**
* Check if upload was successful
*/
if (!$fileUpload::isSuccessful()) {
echo $fileUpload::getErrorMessage();
}
/**
* Make sure to save the $ref UUID so as to be
* able to retrieve the uploaded file(s) from the database.
*/
$fileUpload::getRef()
/**
* Soft delete files
*/
/**
* @param string $ref
* @return bool
*/
FileUpload::deleteAll($ref);
/**
* @param array $ids
* @param string $ref
* @return bool
*/
FileUpload::deleteMultiple($ids, $ref);
/**
* @param int $id
* @param string $ref
* @return bool
*/
FileUpload::deleteOne($id, $ref);
/**
* Permanently delete files from the database and disk
*/
/**
* @param string $ref
* @return bool
*/
FileUpload::forceDeleteAll($ref);
/**
* @param array $ids
* @param string $ref
* @return bool
*/
FileUpload::forceDeleteMultiple($ids, $ref);
/**
* @param int $id
* @param string $ref
* @return bool
*/
FileUpload::forceDeleteOne($id, $ref);
use Ikechukwukalu\Clamavfileupload\Facades\Services\QueuedFileUpload;
QueuedFileUpload::uploadFiles($request); //returns bool|FileUploadModel|EloquentCollection
/**
* Default settings
*
* 'name' => null // This is different from file name
* 'input' => config('clamavfileupload.input', 'file')
* 'folder' => null
* 'hashed' => config('clamavfileupload.hashed', false)
* 'visible' => config('clamavfileupload.visible', true)
* 'disk' => config('clamavfileupload.disk', 'local')
*
*
*/
/**
* You can also overwrite the default settings with custom settings
*/
$settings = [
'folder' => 'pdfs'
];
$fileUpload = new QueuedFileUpload;
$fileUpload::uploadFiles($request, $settings); //returns bool|FileUploadModel|EloquentCollection
/**
* Make sure to save the $ref UUID so as to be
* able to retrieve the uploaded file(s) from the database.
*/
$fileUpload::getRef()
/**
* Soft delete files
*/
/**
* @param string $ref
* @return bool
*/
QueuedFileUpload::deleteAll($ref);
/**
* @param array $ids
* @param string $ref
* @return bool
*/
QueuedFileUpload::deleteMultiple($ids, $ref);
/**
* @param int $id
* @param string $ref
* @return bool
*/
QueuedFileUpload::deleteOne($id, $ref);
/**
* Permanently delete files from the database and disk
*/
/**
* @param string $ref
* @return bool
*/
QueuedFileUpload::forceDeleteAll($ref);
/**
* @param array $ids
* @param string $ref
* @return bool
*/
QueuedFileUpload::forceDeleteMultiple($ids, $ref);
/**
* @param int $id
* @param string $ref
* @return bool
*/
QueuedFileUpload::forceDeleteOne($id, $ref);
use Ikechukwukalu\Clamavfileupload\Facades\Services\NoClamavFileUpload;
NoClamavFileUpload::uploadFiles($request); //returns bool|FileUploadModel|EloquentCollection
/**
* Default settings
*
* 'name' => null // This is different from file name
* 'input' => config('clamavfileupload.input', 'file')
* 'folder' => null
* 'hashed' => config('clamavfileupload.hashed', false)
* 'visible' => config('clamavfileupload.visible', true)
* 'disk' => config('clamavfileupload.disk', 'local')
*
*
*/
/**
* You can also overwrite the default settings with custom settings
*/
$settings = [
'folder' => 'pdfs'
];
$fileUpload = new NoClamavFileUpload;
$fileUpload::uploadFiles($request, $settings); //returns bool|FileUploadModel|EloquentCollection
/**
* Check if upload was successful
*/
if (!$fileUpload::isSuccessful()) {
echo $fileUpload::getErrorMessage();
}
/**
* Make sure to save the $ref UUID so as to be
* able to retrieve the uploaded file(s) from the database.
*/
$fileUpload::getRef()
/**
* Soft delete files
*/
/**
* @param string $ref
* @return bool
*/
NoClamavFileUpload::deleteAll($ref);
/**
* @param array $ids
* @param string $ref
* @return bool
*/
NoClamavFileUpload::deleteMultiple($ids, $ref);
/**
* @param int $id
* @param string $ref
* @return bool
*/
NoClamavFileUpload::deleteOne($id, $ref);
/**
* Permanently delete files from the database and disk
*/
/**
* @param string $ref
* @return bool
*/
NoClamavFileUpload::forceDeleteAll($ref);
/**
* @param array $ids
* @param string $ref
* @return bool
*/
NoClamavFileUpload::forceDeleteMultiple($ids, $ref);
/**
* @param int $id
* @param string $ref
* @return bool
*/
NoClamavFileUpload::forceDeleteOne($id, $ref);
use Illuminate\Http\Request;
use Ikechukwukalu\Clamavfileupload\Models\FileUpload as FileUploadModel;
use Symfony\Component\HttpFoundation\StreamedResponse;
Route::get('/download/hashed/file/{id}', function (Request $request, $id): StreamedResponse {
$file = FileUploadModel::where('id', $id)->first()
return response()->streamDownload(function () use($file) {
echo Crypt::decrypt(Storage::disk($file->disk)->get($file->relative_path));
}, "{$file->name}{$file->extension}");
});
Route::get('/view/hashed/file/{id}', function (Request $request, $id) {
$file = FileUploadModel::where('id', $id)->first();
$decrypted = Crypt::decrypt(Storage::disk($file->disk)->get($file->relative_path));
header("Content-type: {$file->mime_type}");
echo $decrypted;
});
/**
* Dispatches when FileUpload::uploadFiles()
* is called.
*
*/
\Ikechukwukalu\Clamavfileupload\Events\ClamavFileScan::class
/**
* Dispatches when QueuedFileUpload::uploadFiles()
* is called.
*
* @param array $tmpFiles
* @param array $settings
* @param string $ref
*/
\Ikechukwukalu\Clamavfileupload\Events\ClamavQueuedFileScan::class
/**
* Dispatches when all files scanned are safe.
*
* @param array $scanData
*/
\Ikechukwukalu\Clamavfileupload\Events\FileScanPass::class
/**
* Dispatches when a file scanned has a problem.
*
* @param array $scanData
*/
\Ikechukwukalu\Clamavfileupload\Events\FileScanFail::class
/**
* Dispatches when files have been stored and saved into the Database.
*
* @param FileUploadModel|EloquentCollection $files
* @param string $ref
*/
\Ikechukwukalu\Clamavfileupload\Events\SavedFilesIntoDB::class
/**
* Dispatches when clamav is not running.
*
*/
\Ikechukwukalu\Clamavfileupload\Events\ClamavIsNotRunning::class
/**
* Dispatches when file soft delete fails.
*
* @param array $data
*/
\Ikechukwukalu\Clamavfileupload\Events\FileDeleteFail::class
/**
* Dispatches when file soft delete passes.
*
* @param array $data
*/
\Ikechukwukalu\Clamavfileupload\Events\FileDeletePass::class
/**
* Dispatches when permanent file delete from database and disk fails.
*
* @param array $data
*/
\Ikechukwukalu\Clamavfileupload\Events\FileForceDeleteFail::class
/**
* Dispatches when permanent file delete from database and disk passes.
*
* @param array $data
*/
\Ikechukwukalu\Clamavfileupload\Events\FileForceDeletePass::class
/**
* Dispatches when a QueuedFileUpload::deleteAll($ref) is called.
*
* @param string $ref
*/
\Ikechukwukalu\Clamavfileupload\Events\QueuedDeleteAll::class
/**
* Dispatches when a QueuedFileUpload::deleteMultiple($ids, $ref) is called.
*
* @param string $ref
* @param array $ids
*/
\Ikechukwukalu\Clamavfileupload\Events\QueuedDeleteMultiple::class
/**
* Dispatches when a QueuedFileUpload::deleteOne($id, $ref) is called.
*
* @param string $ref
* @param int|string $id
*/
\Ikechukwukalu\Clamavfileupload\Events\QueuedDeleteOne::class
/**
* Dispatches when a QueuedFileUpload::forceDeleteAll($ref) is called.
*
* @param string $ref
*/
\Ikechukwukalu\Clamavfileupload\Events\QueuedForceDeleteAll::class
/**
* Dispatches when a QueuedFileUpload::forceDeleteMultiple($ids, $ref) is called.
*
* @param string $ref
* @param array $ids
*/
\Ikechukwukalu\Clamavfileupload\Events\QueuedForceDeleteMultiple::class
/**
* Dispatches when a QueuedFileUpload::forceDeleteOne($id, $ref) is called.
*
* @param string $ref
* @param int|string $id
*/
\Ikechukwukalu\Clamavfileupload\Events\QueuedForceDeleteOne::class