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 :
<?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()

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();

Can anybody show me how does the simple file upload external form looks like?

Thanks.

tildy
View Replies: View Best Answer
jordanlev replied on at Permalink Best Answer Reply
jordanlev
When a form uploads a file, it needs to have this set:
enctype="multipart/form-data"

So your opening form tag should be this:
<form name="uploadform" method="post" enctype="multipart/form-data" action="<?php echo $this->action('upload_photobook')?>">


There may be other problems as well, but try this first and see if it works.
tildy replied on at Permalink Reply
tildy
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
?>

----------------------------------
<?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();
roa123 replied on at Permalink Reply
Hi,

Were you able to resolve this issue?

cheers,
Ritch
jbx replied on at Permalink Reply 1 Attachment
jbx
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
tildy replied on at Permalink Reply
tildy
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:)