Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Cory_DSL Posted January 6, 2021 Posted January 6, 2021 I have a form in the admin side, with an Upload field. I can't debug or pinpoint where the error is. Same issue with attaching an image in an Editor field. Error: Sorry, an unknown server error occurred when uploading this file. (Error code: -200) $form = new \IPS\Helpers\Form('form'); $form->add(new \IPS\Helpers\Form\Upload( 'acp_points_earnpoints__field_photo', // name $earnPoint->photo ? \IPS\File::get('dslambassador_earnPoints', $earnPoint->photo) : null, // defaultValue false, // required array( 'image' => array( 'maxWidth' => 200, 'maxHeight' => 200, ), 'allowedFileTypes' => array('jpeg', 'jpg', 'png', 'gif'), 'allowStockPhotos' => true, 'storageExtension' => 'dslambassador_EarnPoints', ), // options null, // customValidationCode null, // prefix null, // suffix 'acp_points_earnpoints__field_photo', // id )); if ($values = $form->values()) { $earnPoint = new \IPS\dslambassador\Models\EarnPoint; $earnPoint->name = $values['acp_points_earnpoints__field_name']; $earnPoint->photo = $values['acp_points_earnpoints__field_photo'] ? (string) $values['acp_points_earnpoints__field_photo'] : null; $earnPoint->save(); }
Jock3r Posted January 6, 2021 Posted January 6, 2021 Perhaps the file size is higher than the limit? There are some other possibilities as well, like post_max_size and upload_max_filesize on php.ini.
Cory_DSL Posted January 6, 2021 Author Posted January 6, 2021 Noted on this @Jock3r. I have only been trying to upload an image which is about 32KB though. Will definitely check the logs. Thanks!
Cory_DSL Posted January 7, 2021 Author Posted January 7, 2021 Turns out the module controller class doesn't have: public static $csrfProtected = true; when created via Developer Center, so I added it. The file system/Dispatcher/Admin.php checks if the class is csrfProtected, if not then it will do a session check: /* Unless there is a flag telling us we have specifically added CSRF checks, assume any AdminCP action which contains more than app/module/controller/id (i.e. anything with "do") requires CSRF-protection */ if ( !isset( $this->classname::$csrfProtected ) and array_diff( array_keys( \IPS\Request::i()->url()->queryString ), array( 'app', 'module', 'controller', 'id' ) ) ) { \IPS\Session::i()->csrfCheck(); } Which then causes the Error -200. For the record, the error that I'm experiencing is from the admin's side. I haven't tried the upload feature from the front side, so I'm not sure if this solution is applicable to other Error -200 issues. Hope this helps if others are experiencing it.
Recommended Posts