How to upload files to a folder
Permalink
Now that updating a site from 5.7 to 5.8 will remove all permissions for filesets, how do we modify our existing addons that upload files to a fileset so that they can upload to a folder instead.
Hi MrKDilkington
Thanks for the response...
Actually, I think that limiting files to only be in one folder is not a bad thing.
I would be quite happy to utilise folders instead of filesets if the site users can upload their images directly into their own folder, the permissions for folders will work just the way that fileset permissions used to work.
However, if permissions for filesets CAN be resurrected, that would save me having to modify my custom addons.
But if we really cannot have permissions on filesets then we need the code to enable the existing addons to be modified.
Thanks for the response...
Actually, I think that limiting files to only be in one folder is not a bad thing.
I would be quite happy to utilise folders instead of filesets if the site users can upload their images directly into their own folder, the permissions for folders will work just the way that fileset permissions used to work.
However, if permissions for filesets CAN be resurrected, that would save me having to modify my custom addons.
But if we really cannot have permissions on filesets then we need the code to enable the existing addons to be modified.
I have added a comment to your feature request #5134 in Github.
Thank You.
Thank You.
Andrew has closed this feature request stating file set permissions will not return.
Here is his response..
"File sets are not going to be getting permissions back. File folders hold permissions now. This is much easier to deal with since a file can only be in one folder so we can compute permissions in a much simpler manner.
@weyboat upon upgrading to version 8 if a file is in a file set that has custom permissions, a folder for that file set with those custom permissions will be created and the file will be placed into it, so the file won't become unprotected as you feared."
Andrew is correct in as much that all existing files will be placed into folders and the folder permissions will work as the previous file set permissions did.
However, when users upload new files to the site, they will land in the file set because the existing addons are coded to upload to a file set and not to a folder and all newly uploaded files are exposed to all users!
This brings me back to my original question HOW DO WE UPLOAD FILES TO A FOLDER INSTEAD OF A FILE SET!
Here is his response..
"File sets are not going to be getting permissions back. File folders hold permissions now. This is much easier to deal with since a file can only be in one folder so we can compute permissions in a much simpler manner.
@weyboat upon upgrading to version 8 if a file is in a file set that has custom permissions, a folder for that file set with those custom permissions will be created and the file will be placed into it, so the file won't become unprotected as you feared."
Andrew is correct in as much that all existing files will be placed into folders and the folder permissions will work as the previous file set permissions did.
However, when users upload new files to the site, they will land in the file set because the existing addons are coded to upload to a file set and not to a folder and all newly uploaded files are exposed to all users!
This brings me back to my original question HOW DO WE UPLOAD FILES TO A FOLDER INSTEAD OF A FILE SET!
Have you already found out how to import a file to a folder instead of a fileset?
I finally found out how to move a file to a folder!
See the short code below. Off course some error checking has to be added, but these few lines should do the trick.
See also the move and checkMove functions in the Node class.
https://github.com/concrete5/concrete5/blob/release/8.1.0/concrete/s...
[EDIT]
I just see in the code that it is also possible to place the file directly into a folder. I have not tested this.
See the short code below. Off course some error checking has to be added, but these few lines should do the trick.
$newFile = $fi->import($_FILES['uploadedfile']['tmp_name'], $filename); $folder = FileFolder::getNodeByName("MyFolder"); $newFile->getFile()->getFileNodeObject()->move($folder);
See also the move and checkMove functions in the Node class.
https://github.com/concrete5/concrete5/blob/release/8.1.0/concrete/s...
[EDIT]
I just see in the code that it is also possible to place the file directly into a folder. I have not tested this.
$folder = FileFolder::getNodeByName("MyFolder"); $newFile = $fi->import($_FILES['uploadedfile']['tmp_name'], $filename, $folder);
I can confirm that file set permissions appear to be missing in v8.
My first reaction is that this was an error and they are still there, just not accessible to be set through the interface.
Since a file can only be in one folder, but can be in many file sets, this shows that folders and file sets have different applications and not something that can be swapped for another.
A GitHub issue was made for this:
Feature Request: Restore permissions for file sets #5134
https://github.com/concrete5/concrete5/issues/5134...