Silverstripe 3.1.5 - 上传错误语法错误:意外的令牌<

inv*_*tus 3 silverstripe

我需要上传.svg文件.为此,我将'svg'添加到我的config.yml,将上传字段中允许的扩展名添加到assets /中的.htacces.我的所有资产目录都有CHMOD 777.

文件上传但未附加.而不是我在上传字段中收到此错误SyntaxError:Unexpected token <

File: 
  allowed_extensions:
    - svg
Image: 
  allowed_extensions:
    - svg



$logo->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif', 'svg'));


Deny from all
<FilesMatch "\.(?i:html|htm|xhtml|js|css|bmp|png|gif|jpg|jpeg|ico|pcx|tif|tiff|au|mid|midi|mpa|mp3|ogg|m4a|ra|wma|wav|cda|avi|mpg|mpeg|asf|wmv|m4v|mov|mkv|mp4|ogv|webm|swf|flv|ram|rm|doc|docx|txt|rtf|xls|xlsx|pages|ppt|pptx|pps|csv|cab|arj|tar|zip|zipx|sit|sitx|gz|tgz|bz2|ace|arc|pkg|dmg|hqx|jar|xml|pdf|gpx|kml|svg)$">
    Allow from all
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)

3dg*_*goo 6

Silverstripe(3.1)不允许您将svg文件另存为Image数据类型.这可能与Silverstripe 类使用的PHP GD库(我不确定)有关Image.

相反,您可以将svg文件另存为File数据类型.

要做到这一点,您只需将svg文件类型添加到File allowed_extensionsyml配置文件中(如您在问题中发布的那样):

File: 
  allowed_extensions:
    - svg
Run Code Online (Sandbox Code Playgroud)

在您的Page或DataObject类中添加File关系并设置UploadField:

private static $has_one = array(
    'SVGFile' => 'File'
);

public function getCMSFields()
{
    $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.SVG', UploadField::create('SVGFile', 'SVG File'));

    return $fields;
}
Run Code Online (Sandbox Code Playgroud)

在您的页面模板中,您可以使用文件URL根据需要加载svg.