PHP code example of sar-cubet / file-upload

1. Go to this page and download the library: Download sar-cubet/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/ */

    

sar-cubet / file-upload example snippets


'allowed_file_extensions' => [
    'image' => ['jpeg', 'jpg', 'png', 'gif'],
    'doc' => ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'],
    'text' => ['txt'],
    'others' => []
]

use SarCubet\FileUpload\Facades\Upload;

$validator = Upload::validateFile($request->file('file'));
if ($validator->fails()) {
    return response()->json(['status' => 0, 'errors' => $validator->errors()]);
}

$rules = [
    'png' => 'The file types should be any of the following: jpg,png',
    'max:5120'      => 'The file size should not exceed 5MB'
];

$validator = Upload::validateFile($request->file('file'), $rules);

$scan_file = Upload::scanFile($request->file('file'));
        
if ($scan_file->isFileInfected()) {
    return "This file is found with the malware :" . $scan_file->getMalwareName() . '.';
} else {
    return "This file is safe to upload.";
}

$file = Upload::optimizeImage($request->file('image'), 'moderate'); 

Upload::resize(200, null, $file);

Upload::resize(200, null, $file, true);

$url = Upload::store($file, 's3');

$url = Upload::store($file, 's3', 'your_path');

use Illuminate\Http\Request;

public function chunkFileUpload(Request $request)
{
    $recieve = Upload::receiveChunks($request);
}

if($receive->isUploadComplete()){
    Upload::store($receive->getFile(), 'public');
}

$receive->getLastUploadedChunkIndex();
$receive->getUploadProgressInPercentage();