Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #97 #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/FileAttachmentField.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public function setValue($val, $data = array())
if ($data->hasOneComponent($fieldName)) {
$id = $data->{$fieldName.'ID'};
if ($id) {
$ids[] = $id;
$ids[] = $id;
}
} else if ($data->hasManyComponent($fieldName) || $data->manyManyComponent($fieldName)) {
$files = $data->{$fieldName}();
Expand All @@ -561,7 +561,7 @@ public function setValue($val, $data = array())
if (!$file->exists()) {
continue;
}
$ids[] = $file->ID;
$ids[] = $file->ID;
}
}
}
Expand Down Expand Up @@ -862,7 +862,7 @@ public function isCMS()
{
return Controller::curr() instanceof LeftAndMain;
}

/**
* @note these are user-friendlier versions of internal PHP errors reported back in the ['error'] value of an upload
* @return string
Expand Down Expand Up @@ -914,7 +914,7 @@ private function getUploadUserError($code)
*/
public function upload(HTTPRequest $request)
{

$name = $this->getSetting('paramName');
$files = (!empty($_FILES[$name]) ? $_FILES[$name] : array());
$tmpFiles = array();
Expand All @@ -924,14 +924,14 @@ public function upload(HTTPRequest $request)
$error_message = _t('FileAttachmentField.UPLOADFORBIDDEN', 'Files cannot be uploaded via this form at the current time.');
return $this->httpError(403, $error_message);
}

// No files detected in the upload, this can occur if post_max_size is < the upload size
$value = $request->postVar($name);
if(empty($files) || empty($value)) {
$error_message = _t('FileAttachmentField.NOFILESUPLOADED', 'No files were detected in your upload. Please try again later.');
return $this->httpError(400, $error_message);
}

// Security token check, must go after above check as a low post_max_size can scrub the Security Token name from the request
$form = $this->getForm();
if($form) {
Expand Down Expand Up @@ -1312,8 +1312,8 @@ public function getFileClass($filename = null)
}

if($filename) {
if($defaultClass == "Image"
&& $this->config()->upgrade_images
if($defaultClass == Image::class
&& $this->config()->upgrade_images
&& !Injector::inst()->get($class) instanceof Image
) {
$class = Image::class;
Expand Down