On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Exist a way to give a user the option to Upload his own images in the front end and storage it on a Gallery Album? I'm trying to make it with a Media Source "profile_pics" and a TV "prof_pic" and I'm not having so much luck with the results, Also, I'm using FormIt to upload the image but don't works, I try the form2file snippet but I think I don't set up it well, any Idea?

    > Here is my form:
    [[!+fi.validation_error_message:notempty=`<h1 class="error" style="color:Tomato;"><p>[[!+fi.validation_error_message]]</p></h1>`]]
    <form method="post" action="">
    	    <div class="row gtr-50 gtr-uniform">
    	        <div class="col-6 col-12-mobilep">
                        <div class="row clearfix">
                        <div class="label">Supplementary Files <br /><span class="error">[[+fi.error.nomination_file]]</span></div>
                        <!-- end of .label -->
                        <div class="input"><input id="nomination_file" type="file" name="nomination_file" value="[[+tv.foto_perfil]]" maxlength="100000" /></div>
    
                        <div class="col-12">
                    <ul class="actions special">
                        <li><input type="submit" value="Upload"/></li>
                </ul>
                </div>
            </div>
            </div>
            </div>
    </form>


    > here is the snippet call:
    [[!formIt? 
        &redirectTo=`27`
        &hooks=`formit2file`
        &path = `assets/gallery/3/`
        &extensions = `jpg,JPG,jpeg,JPEG,doc,docx,pdf,txt,png,zip,mov,avi,mpeg,mp4`
        &maxsize = `100`
        &validate=`nomination_file:required`]]

    And here is the form2file snippet code:
      <?php
    $path; // Path from root that user specifies
    $extensions; // allow file extensions
     
    $ext_array = explode(',', $extensions);
     
    // Create path
    $basepath = $modx->config['base_path']; // Site root
    $target_path = $basepath . $path; // root /assets/upload
     
    //$target_path = '/home/emeraldfound/emeraldfoundation.ca/assets/uploads/';
     
    // Get Filename and make sure its good.
    $filename = basename( $_FILES['nomination_file']['name'] );
     
    // Get files extension
    $ext = pathinfo($filename, PATHINFO_EXTENSION);
     
    if($filename != '')
    {
        // Make filename a good unique filename.
        // Make lowercase
        $filename = mb_strtolower($filename);
        // Replace spaces with _
        $filename = str_replace(' ', '_', $filename);
        // Add timestamp
        $filename = date("Ymdgi") . $filename;
     
        // Set final path
        $target_path = $target_path . $filename;
     
        if(in_array($ext, $ext_array))
        {
            if(move_uploaded_file($_FILES['nomination_file']['tmp_name'], $target_path))
            {
                // Upload successful
                //$hook->setValue('nomination_file',$_FILES['nomination_file']['name']);
                $hook->setValue('nomination_file',$filename);
                return true;
            }
            else
            {
                // File not uploaded
                $errorMsg = 'File not uploaded.';
                $hook->addError('nomination_file',$errorMsg);
                return false;
            }
        }
        else
        {
            // File type not allowed
            $errorMsg = 'File not allowed.';
            $hook->addError('nomination_file',$errorMsg);
            return false;
        }
    }
    else
    {
        $hook->setValue('nomination_file','');
        return true;
    }
     
    return true;



      MODx Version: 2.6.5-pl
      Developing in Local Page with:
      > MAMP 5.0
      > PHP 7.2.7