Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverstripe 3.1.5 - Upload Error SyntaxError: Unexpected token <

Tags:

silverstripe

I need to Upload .svg files. To do that I added 'svg' to my config.yml, to the allowed extensions on upload field an to the .htacces in assets/. Also all my assets directories have CHMOD 777.

The File gets uploaded but not attached. Instead of that I receive this error in my upload field 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>
like image 503
invictus Avatar asked Aug 08 '26 13:08

invictus


1 Answers

Silverstripe (3.1) will not allow you to save a svg file as an Image data type. It may be to do with the PHP GD library (I'm not sure), which the Silverstripe Image class uses.

Instead, you can save a svg file as a File data type.

To do this all you need is to add the svg file type to the File allowed_extensions in your yml config file (as you posted in your questions):

File: 
  allowed_extensions:
    - svg

In your Page or DataObject class add the File relation and set your 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;
}

In your page template you can use the file URL to load the svg as you like.

like image 173
3dgoo Avatar answered Aug 13 '26 12:08

3dgoo