bolt / boltforms

Bolt 3 Forms extension - Symfony interface and API for Bolt
http://bolt.cm
GNU General Public License v3.0
52 stars 56 forks source link

File upload aborted as the target directory could not be created. #60

Closed everyx closed 8 years ago

everyx commented 8 years ago

My boltforms.bolt.yml

templates:
  form: boltforms_form.twig
  email: boltforms_email.twig
  subject: boltforms_email_subject.twig
  files: boltforms_file_browser.twig

recaptcha:
  enabled: false
  label: "Please enter the reCaptcha text to prove you're a human"
  public_key: ''
  private_key: ''
  error_message: "The CAPTCHA wasn't entered correctly. Please try again."
  theme: clean

csrf: true

uploads:
  enabled: true                                  # The global on/off switch for upload handling
  base_directory: /files/attachment/             # Outside web root and writable by the web server's user
  filename_handling: prefix                      # Can be either "prefix", "suffix", or "keep"
  management_controller: true                   # Enable a controller to handle browsing and downloading of uploaded files

debug:
  enabled: false
  address: xxx@xxxxxx.com

contact:
  notification:
    enabled: true
    debug: false
    subject: new inquiry
    from_name: notifier               # A field name, specified in the fields: section below
    from_email: xxx@xxxxxxx.com             # A field name, specified in the fields: section below
    replyto_name: name            # A field name, specified in the fields: section below
    replyto_email: email          # A field name, specified in the fields: section below
    to_name: aa     # Must be valid text
    to_email: aa@xxxxxx.com # Must be valid email address
    cc_name: someone
    cc_email: someone@xxxxxxx.com
    attach_files: true
  templates:
   form: partials/_contact_form.twig
   email: partials/_contactform_email.twig
   subject: partials/_contactform_email_subject.twig
  feedback:
    success: Message submission sucessful
    error: There are errors in the form, please fix before trying to resubmit
  fields:
    name:
      type: text
      options:
        required: true
        label: Name
        attr:
          placeholder: Your name...
        constraints: [ NotBlank, {Length: {'min': 3}} ]
    email:
      type: email
      options:
        required: true
        label: Email address
        attr:
          placeholder: Your email...
        constraints: [ NotBlank, Email ]
    message:
      type: textarea
      options:
        required: true
        label: Your message
        attr:
          placeholder: Your message...
          class: myclass
    upload:
      type: file
      options:
        required: false
        label: Attachment
    remote_ip:
      type: hidden
      options:
        label: false
      event:
        name: server_value
        params:
          key: REMOTE_ADDR
    submit:
      type: submit

and `partials/_contact_form.twig

{% form_theme form 'boltforms_custom.twig' %}

{% block boltforms_css %}
<link href="{{ app.paths.extensions }}vendor/bolt/boltforms/css/boltforms.css" rel="stylesheet" type="text/css" />
{% endblock boltforms_css %}

{% if debug %}
<p class="boltform-error">[Debug] Notification debug mode enabled!</p>
{% endif %}

{% if error and app.request.get(formname) %}
<p class="boltform-error">{{ error }}</p>
{% endif %}

{% if message and app.request.get(formname) %}
<p class="boltform-message">{{ message }}</p>
{% endif %}

{% if not sent %}
  {{ html_pre }}
  {% if recaptcha.enabled and recaptcha.theme|default('clean') %}
  <script>
  var RecaptchaOptions = {
    theme : '{{ recaptcha.theme }}'
  };
  </script>
  {% endif %}

  {{ form_start(form, {'attr': {'name': formname, 'class': 'pure-form pure-form-aligned contact-form'}}) }}
    {{ form_errors(form) }}
    <fieldset>
      <span>We’d love to hear from you and answer any questions you may have.</span>
      {% for key, value in fields  %}
      {% if value.config.name != 'submit' %}
      <div class="pure-control-group {% if form[key].vars.attr.class is defined %} boltforms-{{ form[key].vars.attr.class }}-row{% endif %}">
        {{ form_label(form[key]) }}
        {{ form_errors(form[key]) }}
        {{ form_widget(form[key]) }}
      </div>
      {% endif %}
      {% endfor %}

      {% if recaptcha.enabled %}

      {% if not recaptcha.valid %}
      <ul class="boltform-error">
        <li class="boltform-errors">{{ recaptcha.error_message }}</li>
      </ul>
      {% endif %}

      <div class="boltform-row">
        <label for="form_message" class="required">{{ recaptcha.label|trans({}, translation_domain) }}</label>
        <script src="https://www.google.com/recaptcha/api.js?hl={{ htmllang() }}" async defer></script>
        <div class="g-recaptcha" data-sitekey="{{ recaptcha.public_key }}"></div>
      </div>

      {% endif %}

      <div class="pure-controls {% if form.submit.vars.attr.class is defined %} boltforms-{{ form.submit.vars.attr.class }}-row{% endif %}">
        {{ form_widget(form.submit, {'attr': {'class': 'pure-button pure-button-primary'}}) }}
      </div>
    </fieldset>
  {{ form_end(form) }}
{% else %}
  {{ html_post }}
{% endif %}

and the folder is

vagrant@vagrant-ubuntu-trusty-64:~/www/jdhandbagfactory.com/public/files$ ll
total 968
drwxrwxrwx 5 vagrant  www-data   4096 Dec 28 03:54 ./
drwxrwxrwx 8 vagrant  www-data   4096 Dec 16 03:28 ../
drwxrwxrwx 2 vagrant  www-data   4096 Dec 17 06:12 2015-12/
-rwxrwxrwx 1 vagrant  www-data  67817 Nov 29  2014 agriculture-cereals-field-621.jpg*
-rwxrwxrwx 1 vagrant  www-data  34374 Nov 29  2014 alarm-clock-gold-hands-of-a-clock-1778.jpg*
-rwxrwxrwx 1 vagrant  www-data  51381 Nov 29  2014 analog-camera-photography-vintage-1844.jpg*
-rwxrwxrwx 1 vagrant  www-data  50441 Nov 29  2014 apple-desk-iphone-2750.jpg*
-rwxrwxrwx 1 vagrant  www-data  75559 Nov 29  2014 architecture-books-building-2757.jpg*
drwxrwxrwx 2 www-data www-data   4096 Dec 28 09:43 attachment/
-rwxrwxrwx 1 vagrant  www-data  47377 Nov 29  2014 bell-bills-cash-register-2738.jpg*
-rwxrwxrwx 1 vagrant  www-data  53149 Nov 29  2014 blur-breakfast-coffee-271.jpg*
-rwxrwxrwx 1 vagrant  www-data  45555 Nov 29  2014 blur-flowers-home-1093.jpg*
drwxrwxrwx 2 vagrant  www-data   4096 Nov 13 09:24 brands/
-rwxrwxrwx 1 vagrant  www-data  98747 Nov 29  2014 building-frame-garage-1599.jpg*
-rwxrwxrwx 1 vagrant  www-data  46019 Nov 29  2014 california-foggy-golden-gate-bridge-2771.jpg*
-rwxrwxrwx 1 vagrant  www-data  56656 Nov 29  2014 carrot-cooking-eat-1398.jpg*
-rwxrwxrwx 1 vagrant  www-data  39299 Nov 29  2014 configure-disc-jockey-disco-1504.jpg*
-rwxrwxrwx 1 vagrant  www-data  94855 Nov 29  2014 food-fruit-orange-1286.jpg*
-rwxrwxrwx 1 vagrant  www-data 102211 Nov 29  2014 garden-gardening-grass-589.jpg*
-rwxrwxrwx 1 vagrant  www-data    191 Jul 24  2014 .htaccess*
-rwxrwxrwx 1 vagrant  www-data      4 Jul 24  2014 index.html*
-rwxrwxrwx 1 vagrant  www-data  65909 Nov 29  2014 keyboard-old-technology-2318.jpg*

I can receive email when I delete the upload field in the form contact, so could somebody help me with is problem? so many thanks!

GwendolenLynch commented 8 years ago

Your base_directory setting is wrong, it should be an absolute path…

Try:

uploads:
  base_directory: /www/jdhandbagfactory.com/public/files 
everyx commented 8 years ago

Thanks @GawainLynch , I can receive the attachment file now, but I found that the file is not holder in the base_directory, so, it should be a bug? If i change the base_directory outside web root, everything is ok now, so many thanks.

GwendolenLynch commented 8 years ago

:+1: