Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How to create a link to a file in mysite/assets


Go to End


6 Posts   559 Views

Avatar
AD5XJ

Community Member, 35 Posts

26 February 2017 at 8:50am

Edited: 01/03/2017 6:03am

I am trying to create a link to a file in mysite/assets/PDFS with an anchor tag.

I am using the news module to create the article and the link is in the article text.
I can create a link but the CMS cannot find the file even though it exists.

E.G. http://1.1.1.1/mysite/assets/PDFS/mypdf.pdf results in a 404 message. The link is <a href="../mysite/assets/PDFS/mypdf.pdf" />link</a>

I have noticed that I can create a link that uploads a file from my computer to the site and that works fine with a reference link to the uploaded file.

I have checked the permissions. Permissions are the same as assets/Uploads which works fine. The .htaccess file is the same as well.
What am I doing wrong?

Avatar
martimiz

Forum Moderator, 1391 Posts

2 March 2017 at 11:46pm

I'm not sure what you are doing exactly, but '../mysite...' doesn't seem right to me. Your links should be based on the site root, so probably just 'mysite...'

Avatar
AD5XJ

Community Member, 35 Posts

3 March 2017 at 4:13am

Well. thank you for your reply. I am aware of the syntax. I have tried it both ways. No luck. For some reason, references to files like PDFs in mysite/assets/PDFS are unrecognized. Yet in assets/Uploads they are displayed properly.

Can we not link to assets in mysite?

Avatar
martimiz

Forum Moderator, 1391 Posts

3 March 2017 at 7:12am

Yes, it should be possible. I placed this in a Content field, using the html button: <a href="mysite/assets/something.pdf">link</a> and for me that just works. So it must be something else, I guess...

But why you would want to use mysite for that instead of Assets, that is setup to work with the SilverStripe file management I can't really imagine :-)

Avatar
AD5XJ

Community Member, 35 Posts

3 March 2017 at 8:46am

Well my thought was that when major revisions come along and the cms is updated, the assets folder may be part of that. Mysite folder never gets updated as part of a version update.

Avatar
martimiz

Forum Moderator, 1391 Posts

3 March 2017 at 9:55am

Edited: 03/03/2017 9:56am

Well, if you use composer to update, that won't happen. And if you update manually, just leave the assets folder alone - it was really made for this! Mysite is mostly used for code, possibly some special templates and maybe some images, anything non-content. Assets wil hold all files and images for your site content...

SilverStripe file management works together with the assets directory in o so many ways. If you add a link to a file in tinymce 'the silverstripe way', it will in fact be a link to the file ID, meaning that if you were to rename the file, or move it to another folder, the link will still work. The UploadField lets you controll to what folder within the Assets directory you want to upload, how many files, lots of things. There's a secure files module that sets permissions on who can see certain files - and you can manage your files and images and folder structure from within the cms... So my suggestion would really be to work with SilverStripe not 'against it'... :-)

https://docs.silverstripe.org/en/3.1/developer_guides/files/
https://www.silverstripe.org/learn/lessons/working-with-files-and-images?ref=hub