mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Improve document upload efficiency
This commit is contained in:
parent
f7d8f819b6
commit
ae6fa5ab9b
@ -71,8 +71,9 @@ class DocumentRepository extends BaseRepository
|
|||||||
$documentType = Document::$extensions[$extension];
|
$documentType = Document::$extensions[$extension];
|
||||||
$filePath = $uploaded->path();
|
$filePath = $uploaded->path();
|
||||||
$name = $uploaded->getClientOriginalName();
|
$name = $uploaded->getClientOriginalName();
|
||||||
|
$size = filesize($filePath);
|
||||||
|
|
||||||
if(filesize($filePath)/1000 > MAX_DOCUMENT_SIZE){
|
if($size/1000 > MAX_DOCUMENT_SIZE){
|
||||||
return Response::json([
|
return Response::json([
|
||||||
'error' => 'File too large',
|
'error' => 'File too large',
|
||||||
'code' => 400
|
'code' => 400
|
||||||
@ -87,7 +88,9 @@ class DocumentRepository extends BaseRepository
|
|||||||
$document = Document::createNew();
|
$document = Document::createNew();
|
||||||
$disk = $document->getDisk();
|
$disk = $document->getDisk();
|
||||||
if(!$disk->exists($filename)){// Have we already stored the same file
|
if(!$disk->exists($filename)){// Have we already stored the same file
|
||||||
$disk->put($filename, file_get_contents($filePath));
|
$stream = fopen($filePath, 'r');
|
||||||
|
$disk->put($filename, $stream);
|
||||||
|
fclose($stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is an image; check if we need to create a preview
|
// This is an image; check if we need to create a preview
|
||||||
@ -100,11 +103,9 @@ class DocumentRepository extends BaseRepository
|
|||||||
if(in_array($documentType, array('image/gif','image/bmp','image/tiff'))){
|
if(in_array($documentType, array('image/gif','image/bmp','image/tiff'))){
|
||||||
// Needs to be converted
|
// Needs to be converted
|
||||||
$makePreview = true;
|
$makePreview = true;
|
||||||
} else {
|
} else if($width > DOCUMENT_PREVIEW_SIZE || $height > DOCUMENT_PREVIEW_SIZE){
|
||||||
if($width > DOCUMENT_PREVIEW_SIZE || $height > DOCUMENT_PREVIEW_SIZE){
|
|
||||||
$makePreview = true;
|
$makePreview = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if($documentType == 'image/bmp' || $documentType == 'image/tiff'){
|
if($documentType == 'image/bmp' || $documentType == 'image/tiff'){
|
||||||
if(!class_exists('Imagick')){
|
if(!class_exists('Imagick')){
|
||||||
@ -156,7 +157,7 @@ class DocumentRepository extends BaseRepository
|
|||||||
|
|
||||||
$document->path = $filename;
|
$document->path = $filename;
|
||||||
$document->type = $documentType;
|
$document->type = $documentType;
|
||||||
$document->size = filesize($filePath);
|
$document->size = $size;
|
||||||
$document->name = substr($name, -255);
|
$document->name = substr($name, -255);
|
||||||
|
|
||||||
if(!empty($imageSize)){
|
if(!empty($imageSize)){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user