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>

    > here is the snippet call:
        &path = `assets/gallery/3/`
        &extensions = `jpg,JPG,jpeg,JPEG,doc,docx,pdf,txt,png,zip,mov,avi,mpeg,mp4`
        &maxsize = `100`

    And here is the form2file snippet code:
    $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
                return true;
                // File not uploaded
                $errorMsg = 'File not uploaded.';
                return false;
            // File type not allowed
            $errorMsg = 'File not allowed.';
            return false;
        return true;
    return true;

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