Adding files to file manager
Permalink 1 user found helpful
Okay, so I've created a theme package with some custom icons and for the life of me, I CANNOT get the files to load into the file manager. The rest of the package loads fine??
I used the code from the documentation in my controller file, because that's where I figured that it goes:
Please help, I've been at this for two days and have yet to see any one example.
I used the code from the documentation in my controller file, because that's where I figured that it goes:
Loader::library("file/importer"); $fi = new FileImporter(); $newFile = $fi->import('/themes/playful/images/social-media-icons/facebook.png','facebook.png');
Please help, I've been at this for two days and have yet to see any one example.
Thanks jasteele123!
My packages directory is: packages/theme_playful(controller.php sits here)/themes/playful/images/social-media-icons
I thought writing the path relative to the controller would work, but as you saw...no go.
I tried adding the return echo, but since the code is in the controller, the echo doesn't print anywhere that I can see. I tried adding the same code to one of the page type files, but that was a bust as well. I checked the logs table in the database. I didn't see anything to point me in the right direction there.
Any other thoughts?
My packages directory is: packages/theme_playful(controller.php sits here)/themes/playful/images/social-media-icons
I thought writing the path relative to the controller would work, but as you saw...no go.
I tried adding the return echo, but since the code is in the controller, the echo doesn't print anywhere that I can see. I tried adding the same code to one of the page type files, but that was a bust as well. I checked the logs table in the database. I didn't see anything to point me in the right direction there.
Any other thoughts?
Thanks - That logged an invalid file error, so now to work from there.
RJ
RJ
I'm guessing it should be packages/theme_playful/themes/ instead of /themes/
FYI, technically the error testing should be:
instead of:
Good luck!
FYI, technically the error testing should be:
if ($newFile instanceof FileVersion) {
instead of:
if(is_object($newFile)) {
Good luck!
Hi RJ,
I think this might be what you want to do. This code is untested, but should be fairly close :)
Hope that helps!
John
I think this might be what you want to do. This code is untested, but should be fairly close :)
Loader::library('file/importer'); $fi = new FileImporter(); $fh = Loader::helper('file'); // $dir = $pkg->packagePath(); $iconPath = $dir. '/themes/playful/images/social-media-icons'; $files = $fh->getDirectoryContents($iconPath); foreach($files as $file) { $newFile = $fi->import($iconPath'. '/'. $file, $file); if ($newFile instanceof FileVersion) { continue; // or add to sets or whatever } else { Log::addEntry($fi->getErrorMessage($newFile)); }
Viewing 15 lines of 16 lines. View entire code block.
Hope that helps!
John
Thanks so much John.
The path that I used was the problem it has to be absolute from the root package directory, not relative to the controller.
For anyone's reference who may find this the end code did use John's idea of making the whole thing extensible by concatinating the path with the individual files in an array.
I adjusted the other code to:
It tested fine and didn't throw any error, but wouldn't load any files either. When I took out the if/else - it started loading fine.
Thanks again! You have saved me hours and hours of bashing my head against a keyboard...my keyboard also thanks you. :-)
The path that I used was the problem it has to be absolute from the root package directory, not relative to the controller.
For anyone's reference who may find this the end code did use John's idea of making the whole thing extensible by concatinating the path with the individual files in an array.
Loader::library('file/importer'); $fh = Loader::helper('file'); //load icons to file manager $fi = new FileImporter(); $iconPath = 'packages/theme_playful/themes/playful/images/social-media-icons/'; $files = $fh->getDirectoryContents($iconPath); foreach($files as $file) { $newFile = $fi->import($iconPath.$file); }
I adjusted the other code to:
Loader::library('file/importer'); $fi = new FileImporter(); $fh = Loader::helper('file'); $iconPath = 'packages/theme_playful/themes/playful/images/social-media-icons/'; $files = $fh->getDirectoryContents($iconPath); foreach ($files as $file) { $newFile = $fi->import($iconPath. $file); if ($newFile instanceof FileVersion) { continue; // or add to sets or whatever } else { Log::addEntry($fi->getErrorMessage($newFile)); } }
It tested fine and didn't throw any error, but wouldn't load any files either. When I took out the if/else - it started loading fine.
Thanks again! You have saved me hours and hours of bashing my head against a keyboard...my keyboard also thanks you. :-)
Untested, but should get you on the right path...