Importing New Files
Permalink
I am trying to create a single page for site users to import images to their own fileset.
I have been using the information on this C5 Document.
http://documentation.concrete5.org/developers/working-with-files-an...
But I can't get it to upload an image, I can get the image selected but it does not upload, instead I get a 'Page Not Found' error?
Has anybody got a working example of this code?
I have been using the information on this C5 Document.
http://documentation.concrete5.org/developers/working-with-files-an...
But I can't get it to upload an image, I can get the image selected but it does not upload, instead I get a 'Page Not Found' error?
Has anybody got a working example of this code?
I have modified my question to remove the code sample.
Looks like nobody managed to get this working?
What version of C5 are you using? Can you provide examples to your code so that people can help you try to debug?
Hi Hutman
I am developing on Concrete 5.8.0.3
I put the code together as per the instructions on the page I linked to but have since deleted it.
This was why I was asking if anyone had managed to create code that worked as per the instructions?
I am developing on Concrete 5.8.0.3
I put the code together as per the instructions on the page I linked to but have since deleted it.
This was why I was asking if anyone had managed to create code that worked as per the instructions?
Unfortunately there is little or no documentation for 5.8 at this time, so it's unlikely somebody would have done this so far. It should be similar to 5.7 though which is why posting code is a good idea to get help.
The code I put together was this, although it is obviously wrong, I would welcome your input..
<?php function submit() { $error = \Concrete\Core\File\Importer::E_PHP_FILE_ERROR_DEFAULT; if (isset($_FILES['photo']) && is_uploaded_file($_FILES['photo']['tmp_name'])) { $file = $_FILES['photo']['tmp_name']; $filename = $_FILES['photo']['name']; $importer = new \Concrete\Core\File\Importer(); $result = $importer->import($file, $filename); if ($result instanceof \Concrete\Core\File\Version) { $this->redirect('/my/success/page'); } else { $error = $result; } } else if (isset($_FILES['photo'])) {
Viewing 15 lines of 29 lines. View entire code block.
I am quite happy to roll back to 5.7 if I can get a working example for that version..
Your code seems to import the file as-is in 5.7 but I get the same 404 issue with 5.8 that you are getting.
I tested this by creating an External Form and putting the contents of your submit function into an action_submit function in the form's controller and it worked perfectly.
I tested this by creating an External Form and putting the contents of your submit function into an action_submit function in the form's controller and it worked perfectly.
Thanks Hutman
At least I know that if I roll back to 5.7 I can get it working.
I will settle for that until 5.8 documentation is available.
Once again thank you for your help..
At least I know that if I roll back to 5.7 I can get it working.
I will settle for that until 5.8 documentation is available.
Once again thank you for your help..
Yep
I rolled back to 5.7 and got it working with your help..
Just need to get the image to load into a users fileset.
I have tried creating a page attribute with the fileset name but so far no joy.
Any thoughts on this?
I rolled back to 5.7 and got it working with your help..
Just need to get the image to load into a users fileset.
I have tried creating a page attribute with the fileset name but so far no joy.
Any thoughts on this?
Is this only available to users who are logged in? If so you could store the Fileset ID as a User Attribute.
What code do you have that isn't working?
What code do you have that isn't working?
Hi Hutman
Yes it is for users who are logged in and I am open to any suggestions you might have.
I have hacked various bit of code into the controller file to no avail.
If I created a user attribute called fileset_name how would I add that to the existing controller code listed below..
Yes it is for users who are logged in and I am open to any suggestions you might have.
I have hacked various bit of code into the controller file to no avail.
If I created a user attribute called fileset_name how would I add that to the existing controller code listed below..
<?php namespace Concrete\Block\ExternalForm\Form\Controller; use Concrete\Core\Controller\AbstractController; use FileSet; use FileList; class UploadImage extends AbstractController { function action_submit() { $error = \Concrete\Core\File\Importer::E_PHP_FILE_ERROR_DEFAULT; if (isset($_FILES['photo']) && is_uploaded_file($_FILES['photo']['tmp_name'])) { $file = $_FILES['photo']['tmp_name']; $filename = $_FILES['photo']['name']; $importer = new \Concrete\Core\File\Importer(); $result = $importer->import($file, $filename);
Viewing 15 lines of 26 lines. View entire code block.
Just read your comment again 'User ID' so I can create an attribute that holds the User 'ID',
Yes, that makes perfect sense..
Still not sure how to implement it though.
Yes, that makes perfect sense..
Still not sure how to implement it though.
Try something like this
<?php namespace Concrete\Block\ExternalForm\Form\Controller; use Concrete\Core\Controller\AbstractController; use FileSet; use FileList; use Concrete\Core\User\User; use Concrete\Core\User\UserInfo; class UploadImage extends AbstractController { function action_submit() { //this is based on the assumption that the user will never be a guest $u = new User(); $ui = UserInfo::getByID($u->getUserID()); $fileSetId = $ui->getAttribute('file_set_id'); //user attribute handle 'file_set_id' exists and is set to a number
Viewing 15 lines of 37 lines. View entire code block.
Yes
You Beauty! it works perfectly!
I can't thank you enough..
You Beauty! it works perfectly!
I can't thank you enough..