0

How can I assign to the upload field a maximum size of 4MB? I tried this

$imageField = new SortableUploadField('Images', 'Images');
$imageField->setOverwriteWarning(FALSE);
$imageField->setAllowedMaxFileNumber(40);
$sizeMB = 4; // 4 MB
$size = $sizeMB * 1024 * 1024; // 2 MB in bytes
$imageField->getValidator()->setAllowedMaxFileSize($size); 

but I get an Internal server error / forbidden message.

Thank you

Steve
  • 1,036
  • 2
  • 13
  • 31

3 Answers3

2

Now it works for me:

I found out that /framework/filesystem/GD.php needs more than 64MB. Therefore i had to set php_value memory_limit 128M

Steve
  • 1,036
  • 2
  • 13
  • 31
1

You are setting the max upload file size for the UploadField here. the code seems correct.

however my guess is that you only set it here, but your server still only allows 2MB see this answer https://stackoverflow.com/a/3263496/1119263 for how to change the upload size allowed by the webserver/php.

Community
  • 1
  • 1
Zauberfisch
  • 3,870
  • 18
  • 25
  • The server allows more than 2MB. I found out that after the upload of the "to big image" it is not possible anymore to go in the CMS menu "Files". By clicking on "Files" i get the same error message: Internal server error. Could it maybe be a problem that I do not resize the images when uploading them? – Steve Nov 21 '13 at 15:41
-2
$uploadField = new UploadField(
    $name = 'AttachedImages',
    $title = 'Attached Images'
);
$uploadField->getValidator()->setAllowedMaxFileSize( 4 * 1024 * 1024 );
LevB
  • 2,326
  • 3
  • 16
  • 14
  • This doesn't work for me. When progress bar finishes I get an Internal server error – Steve Nov 21 '13 at 13:49
  • it does work if all other parameters are correct. Which obviously was not the case in this question. Especially obvious because your code is already in the question. – Zauberfisch Nov 22 '13 at 02:25
  • Question is related to SilverStripe, not other parameters. Especially obvious to check PHP settings before asking about CMS settings. – LevB Nov 22 '13 at 02:46
  • So if someone asks you why the .exe is not running then would tell him how to fix hit rather than asking if he is on a mac or linux before? – Zauberfisch Nov 22 '13 at 03:10
  • Yes. My fault is that I guess people are technically skilled to address direct question. – LevB Nov 22 '13 at 03:18
  • I thought that when I set a php_value memory_limit of 64M it should be enough for running silverstripe since in the documentation was recommended 48M. That's why I supposed there is something wrong in my code.. – Steve Nov 22 '13 at 08:49