file uploader external form
Permalink
Hi , I am new in a concrete 5 development, so I need a little help.
I tried to create an external form with file upload:
here is the upload form code :
I tried to change the backend code to this one, but it still not working and I get an error message ( An unknown error occurred while uploading the file. Please check that file uploads are enabled, and that your file does not exceed the size of the post_max_size or upload_max_filesize variables. File Uploads: 1 Max Upload File Size: 2M Post Max Size: 8M I can see the filename in a $_REQUEST variable.
Can anybody show me how does the simple file upload external form looks like?
Thanks.
I tried to create an external form with file upload:
here is the upload form code :
<?php $form = Loader::helper('form'); defined('C5_EXECUTE') or die("Access Denied."); $al = Loader::helper('concrete/asset_library'); ?> <script type="text/javascript" charset="utf-8"> $(function() { $("input[type=file]").filestyle({ image: "/concrete/images/browse_btn.png", imageheight : 30, imagewidth : 120, width : 200 }); }); function submitform()
Viewing 15 lines of 43 lines. View entire code block.
I tried to change the backend code to this one, but it still not working and I get an error message ( An unknown error occurred while uploading the file. Please check that file uploads are enabled, and that your file does not exceed the size of the post_max_size or upload_max_filesize variables. File Uploads: 1 Max Upload File Size: 2M Post Max Size: 8M I can see the filename in a $_REQUEST variable.
$val = Loader::helper('validation/form'); Loader::library("file/importer"); $cf = Loader::helper('file'); $fp = FilePermissions::getGlobal(); if (!$fp->canAddFiles()) { die(_("Unable to add files.")); } if (isset($_POST['fID'])) { // we are replacing a file $fr = File::getByID($_REQUEST['fID']); } else { $fr = false; } $destination_path = getcwd().DIRECTORY_SEPARATOR."bookfiles".DIRECTORY_SEPARATOR; $fi = new FileImporter();
Viewing 15 lines of 17 lines. View entire code block.
Can anybody show me how does the simple file upload external form looks like?
Thanks.
I got an example code from jbx.
----------------------------------
<?php defined('C5_EXECUTE') or die("Access Denied."); $form = Loader::helper('form'); if (isset($fileInfo)) { ?> <p> Your file with fID <?php echo $fileInfo['fID'] ?> has been successfully added to the Filemanager at the following location:<br /> <a href="<?php echo $fileInfo['link'] ?>" title="<?php echo $fileInfo['name'] ?>"> <?php echo $fileInfo['name'] ?> </a> </p> <?php } // The most important thing to remember here is the enctype attribute // Without that, your file will never get uploaded ?>
Viewing 15 lines of 23 lines. View entire code block.
----------------------------------
<?php defined('C5_EXECUTE') or die("Access Denied."); class FileUploadExternalFormBlockController extends BlockController { public function action_file_upload() { Loader::library("file/importer"); $fi = new FileImporter(); /** * $fi->import handles importing the file into the Filemanager * 1st param: The temporary uploaded file * 2nd param: The actual filename * returns: A file object */ $file = $fi->import($_FILES['myFile']['tmp_name'], $_FILES['myFile']['name']); $path = $file->getRelativePath();
Viewing 15 lines of 26 lines. View entire code block.
Hi,
Were you able to resolve this issue?
cheers,
Ritch
Were you able to resolve this issue?
cheers,
Ritch
Yep - I built a mini form for her that gives a good starting point.
I've attached it here for reference. Let me know if it helps :)
Jon
I've attached it here for reference. Let me know if it helps :)
Jon
Yes, As jbc said, he created a simple fileuploader form for me, because I forget to use some things, for example the most important enctype.
Jbx , I think it is the best way if you put this code into the docs/tutorial site too. And thank you again.
I created a external form, with jwuery popup, I post the form the action php, and I get back an js code, and after the file upload succesful is showing.
So thank you again, you are very helpful:)
Jbx , I think it is the best way if you put this code into the docs/tutorial site too. And thank you again.
I created a external form, with jwuery popup, I post the form the action php, and I get back an js code, and after the file upload succesful is showing.
So thank you again, you are very helpful:)
I know this thread is pretty old, but can the above code be modified to work the 5.8? I tried playing around with it, but I didn't get very far (granted I'm a novice with concrete5 and trying to wrap my head round external forms).
Ideally, I'm trying to modify the code here: http://www.html-form-guide.com/email-form/php-email-form-attachment... to work with concrete5.
I want to be able to upload a file (probably outside the file manager), using an external form, and then email that file as an attachment.
I've done a lot of searching, and found threads that are all related to this, but no posted solution. I'm hoping if I can at least get the file uploaded, I can use the mail documentationo send the attachment.
Ideally, I'm trying to modify the code here: http://www.html-form-guide.com/email-form/php-email-form-attachment... to work with concrete5.
I want to be able to upload a file (probably outside the file manager), using an external form, and then email that file as an attachment.
I've done a lot of searching, and found threads that are all related to this, but no posted solution. I'm hoping if I can at least get the file uploaded, I can use the mail documentationo send the attachment.
Hi drdobell,
Using the sample External Form block form in the core and reading the documentation will give you the information you need to accomplish your task
Test Form sample External Form
https://github.com/concrete5/concrete5/tree/develop/concrete/blocks/...
Interactive Blocks
https://documentation.concrete5.org/developers/working-with-blocks/c...
Importing New Files
https://documentation.concrete5.org/developers/working-with-files-an...
Sending Mail
https://documentation.concrete5.org/developers/sending-mail...
Using the sample External Form block form in the core and reading the documentation will give you the information you need to accomplish your task
Test Form sample External Form
https://github.com/concrete5/concrete5/tree/develop/concrete/blocks/...
Interactive Blocks
https://documentation.concrete5.org/developers/working-with-blocks/c...
Importing New Files
https://documentation.concrete5.org/developers/working-with-files-an...
Sending Mail
https://documentation.concrete5.org/developers/sending-mail...
enctype="multipart/form-data"
So your opening form tag should be this:
There may be other problems as well, but try this first and see if it works.