We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16633
    • 116 Posts
    All of a sudden my formit2file snippet is causing a parse error

    Parse error: syntax error, unexpected '<' in /home/nacgbol1/public_html/emeraldfoundation.ca/core/cache/elements/modsnippet/30.include.cache.php on line 7

    When I look at that file this is what you see

    <?php
    function elements_modsnippet_30($scriptProperties= array()) {
    global $modx;
    if (is_array($scriptProperties)) {
    extract($scriptProperties, EXTR_SKIP);
    }
    <?php
    
    $output = true;
    
    $path;
    
    $extensions;


    So it is easy to see the error, but I do not know how to fix it. Here is my formit2file code:
    <?php
    $output = true;
    $path;
    $extensions;
    $ext_array = explode(',', $extensions);
    $uploadpath = $path;
    $target_path = $modx->config['base_path'] . $uploadpath;
    $submittedfiles = array_keys($_FILES);
     
    foreach ($submittedfiles as $sf) {
        $filename = basename( $_FILES[$sf]['name'] );
        $ext = pathinfo($filename, PATHINFO_EXTENSION);
        $ext = mb_strtolower($ext); // case insensitive
     
        if($filename != '') {
            if(in_array($ext, $ext_array)) {
                $filename = mb_strtolower($filename);
                $filename = str_replace(' ', '_', $filename);
                $filename = date("Ymd_Gis_") . $filename;
                 
                $myTarget = $target_path . $filename;
                 
                mkdir($target_path, 0755, true);
                 
                if(move_uploaded_file($_FILES[$sf]['tmp_name'], $myTarget)) {
                    $modx->setPlaceholder('fi.'.$sf.'_new', $myTarget);
                    
                    if (!chmod($myTarget, 0644)) { /*some debug function*/ }
                    
                    $hook->setValue($sf, $filename);
                } else {
                    $errorMsg = 'There was a problem uploading the file.';
                    $hook->addError($sf, $errorMsg);
                    $output = false;
                }         
            } else {
                $errorMsg = 'Type of file not allowed.';
                $hook->addError($sf, $errorMsg);
                $output = false;
            }     
        } else {
            $hook->setValue($sf, '');
        } 
    } 
    return $output;
    [ed. note: landonpoburan last edited this post 12 years, 2 months ago.]
      --
      Landon Poburan
      Web Designer and Developer

      http://www.categorycode.ca
      http://www.landonp.com
      • 16633
      • 116 Posts
      In my formit call, I moved formit2file to the last hook and the parse error is gone.

      [[!FormIt?
          &hooks=`spam,formit2resource,email,FormItAutoResponder,redirect,formit2file`
          &preHooks=`resource2formit`
        --
        Landon Poburan
        Web Designer and Developer

        http://www.categorycode.ca
        http://www.landonp.com
        • 16633
        • 116 Posts
        But with that, the files aren't uploaded.

        PS I am using MODX Reve 2.0.4-pl2 and formit 1.4
          --
          Landon Poburan
          Web Designer and Developer

          http://www.categorycode.ca
          http://www.landonp.com
          • 16633
          • 116 Posts
          Issue has been resolved.
            --
            Landon Poburan
            Web Designer and Developer

            http://www.categorycode.ca
            http://www.landonp.com