Search

How have you guys handled uploading multiple files in a single shot before?

As I see it, there are a number of ways:

  1. Create an extension field that supports the multiple option in HTML5 (which safari only supports, ff 3.5 might) and creates tables to handle multiple files. I’ve implemented this in a very rudimentary way that works, but you lose the ability to easily track metadata for each file and the ability to assign multiple files to multiple sections.
  2. Create a front-end form using the allow-multiple option and with some JS magic populate the form with fields[0..n][upload-file]. Which might work and might be an easy way.
  3. Create an extension to modify the backend to add a dialog that supports adding multiple entries. I’m not even sure how to do this.
  4. Create a new extension using something like Uploadify and a modified text/upload field to just store the link to the file and let uploadify handle the uploading. This also might be an easy way.

Thoughts?

Number 2 would be the obvious choice since it’s do-able out o’ the box. Do you want to upload n number, or limit to a fixed number? If the former, you would be best using a separate Files or Assets section which is linked back to your main entry.

With an allow-multiple event you can then submit multiple files and link them up. You could possibly use Rowan’s Sub Section field to make this Files section inline inside of the main entry.

I started an extension to add Uploadify to upload fields in the backend:
http://getsymphony.com/forum/discussions/21595/

The problem here is, as you say, files are uploaded through Uploadify’s own PHP script which bypasses Symphony’s validation goodness. I’m after someone who knows more than I to polish it off by integrating with an upload field validation itself, so Uploadify remains as a thin JavaScript layer, leaving the uploading native to Symphony.

I’m still using a separate files section, but this whole thing arose when I needed to jam 1000 images in the section. While this might be solved by using an external service, well, that just wouldn’t be any fun.

Option number 2 does seem like the easiest, but I think it could be handled better, either with uploadify or even ftp. The issue then is what you described in the other post. That we’d need to instantiate the field.

In the case of mass-entries do what symphony normally does, except calling processRawFieldData and checkRawFieldData without POSTing since the file’s already uploaded, but still create the entry.

In your case, just simply not creating the entry and only looking at the field. I assume you’ve looked at how symphony processes entries; to create an upload field object (this is all in the upload.php or whatever uploadify calls) this might work, someone could chime in with some knowledge ;p

  1. it looks like you’d need to instantiate it by creating an engine? object (which is what the root /index.php does I take it), this seems like the only unknown, perhaps something like this:

    define('DOCROOT', rtrim(dirname(__FILE__), '/'));
    define('DOMAIN', rtrim(rtrim($_SERVER['HTTP_HOST'], '/') . dirname($_SERVER['PHP_SELF']), '/'));
    require_once(CORE . '/class.frontend.php');
    $Frontend = Frontend::instance();
    $this->_engine = $this->_ParentCatalogue['frontend']
    
  2. create a SectionManager Object, $sectionManager = new SectionManager($this->_engine); fetch the section you’re in by id, $sections = $sectionManager->fetch($id, 'ASC', 'name');, you should be able to pass the section id into uploadify (I’m sure it exists somewhere in $_GLOBALS)

  3. fetch all the fields out of the section $section->fetchFields(), find your field, it should be an actual field object, and at which point you can:

  4. use this code in the field.upload.php

    $data['name'] = Lang::createFilename($data['name']);
    if($field->get('validator') != NULL){
        $rule = $field->get('validator');
    
        if(!General::validateString($data['name'], $rule)){
            $message = __("File chosen in '%s' does not match allowable file types for that field.", array($this->get('label')));
                return self::__INVALID_FIELDS__;
        }
    }
    

This is bits #1-#part of 3

<?php

  define('DOCROOT', rtrim(dirname(__FILE__), '/'));
  define('DOMAIN', rtrim(rtrim($_SERVER['HTTP_HOST'], '/') . dirname($_SERVER['PHP_SELF']), '/'));

  require(DOCROOT . '/symphony/lib/boot/bundle.php');
    require_once(CORE . '/class.administration.php');
    include_once(TOOLKIT . '/class.sectionmanager.php');

    $Admin = Administration::instance();



    $sectionManager = new SectionManager($Admin);
    $sections = $sectionManager->fetch(NULL, 'ASC', 'name');
    foreach ($sections as $section)
        print_r($section->fetchFields());
  exit();

?>

Just substitute NULL for the $id, and continue, and it should work!

Actually I guess the best way to do it would just to do this in the extension and pass the validator to the uploadify script and check it in there.

If you check out my extension, I already do this. I grab the validation regular expression and the upload destination folder, and pass it to the JavaScript for each individual upload field. This is a halfway-house, but won’t work for fields such as the Hashed Upload and Unique Upload, which manipulate the filename during upload.

Thanks for the pointers, I’ll be giving this a go in the next week or two.

Well, I decided on trying #3.

I created an extension that adds multiple files from a single folder, and it works with any upload field, BUT, since they all use is_uploaded_file and move_uploaded_file I had to avoid using processRawFieldData, which probably means it’ll only work for the default upload field.

I’ll put it on github soon, but surely there has to be a better way.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details