PHP code example of groovili / rest-uploader-bundle
1. Go to this page and download the library: Download groovili/rest-uploader-bundle 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/ */
groovili / rest-uploader-bundle example snippets
public function registerBundles()
{
$bundles = [
// ...
new Groovili\RestUploaderBundle\RestUploaderBundle(),
// ...
];
// ...
}
/** @var @UploadedFile $upload */
$upload = $request->files->get('file');
if (isset($upload)) {
$form = $this->createFormBuilder()
->add('file', RestFileType::class, [
'allow_delete' => true,
'validate_extensions' => true,
'validate_size' => true,
'private' => false,
])
->getForm();
$form->handleRequest($request);
$clearMissing = $request->getMethod() != 'PATCH';
$form->submit(['file' => $upload], $clearMissing);
$data = $form->getData();
if (isset($data['file'])) {
/** @var File $file */
$file = $data['file'];
$em = $this->getDoctrine()->getManager();
$em->persist($file);
$em->flush();
}
}
/**
* $file = ['file' => ['id' => 8]]
*/
$file = json_decode($request->getContent(), true);
$form = $this->createFormBuilder()
->add('file', RestFileType::class, [
'allow_delete' => true,
'validate_extensions' => true,
'validate_size' => true,
'private' => false,
])
->getForm();
$form->handleRequest($request);
$clearMissing = $request->getMethod() != 'PATCH';
$form->submit($file , $clearMissing);
/**
* $file = ['file' => ['id' => 8, 'delete' => true]]
*/
$file = json_decode($request->getContent(), true);
$form = $this->createFormBuilder()
->add('file', RestFileType::class, [
'allow_delete' => true,
'validate_extensions' => true,
'validate_size' => true,
'private' => false,
])
->getForm();
$form->handleRequest($request);
$clearMissing = $request->getMethod() != 'PATCH';
$form->submit($file , $clearMissing);
$em = $this->getDoctrine()->getManager();
$em->flush();
/** @var @UploadedFile $upload */
$upload = $request->files->get('file');
if (isset($upload)) {
$validator = $this->container->get('rest_uploader.validator');
$uploader = $this->container->get('rest_uploader.manager');
if ($validator->isExtensionAllowed($upload) && $validator->isSizeValid($upload)){
/** @var File $file */
$file = $uploader->upload($upload, false);
}
}