We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3722
    • 171 Posts
    I am looking for a way for the client to upload files to different folders in /assets/files/...
    I would like to have the file assigned a title or name different then the file name.
    I could then list the files on a page using Ditto or something.

    Example:
    File name is "newsletter_081210.pdf"
    I would like the user to create a more friendly title on upload "Newsletter for August, 2010"

    Can this be done with eForm or something else?

    Thanks
    BG66
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Yes, it can. In eForm’s form, have the field for the user to enter the filename. Then use a snippet/function to handle the uploaded file, specifying the filename (in the $fields array) to move the file to in the move_uploaded_file function. I would be inclined to use the eFormOnValidate event; this event passes the &fields array which will have all the fields from the form, and of course you can use the PHP global $_FILES array to access the uploaded file.

      http://www.php.net/manual/en/features.file-upload.post-method.php
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 4971
        • 964 Posts
        I use TVs... one for the file name, one for the displayed name,
        sometimes one for the file extension...

        Then I use ditto to make a table of the files... filename and file type icon.

        The file TV gives you access to the resource browser where you can
        upload to the configured directory.
          Website: www.mercologia.com
          MODX Revo Tutorials:  www.modxperience.com

          MODX Professional Partner
          • 3722
          • 171 Posts
          Thanks, I will try again with your suggestions.
          BG66
            • 3722
            • 171 Posts
            OK, I ended up using the FileUpload Snippet.
            I am now able to upload files to my directory.

            I added a TV to the FileUploadForm like this:
             <form enctype="multipart/form-data" action="[~[*id*]~]" method="post">
            
               <input type="hidden" name="formid" value="[+fileupload.formid+]" />
               <!-- MAX_FILE_SIZE must precede the file input field -->
               <input type="hidden" name="MAX_FILE_SIZE" value="[+fileupload.maxsize+]" />
            
              <p>Title:  <input type="text" name="Title" value="[+uploadTitle+]" /></p><br />
              <p>Select a file:<input name="userfile[]" type="file" /></p><br />
              <p><input type="submit" value="Upload file" /></p>
            
             </form>
            <p>

            with this line:
            <p>Title:  <input type="text" name="Title" value="[+uploadTitle+]" /></p><br />


            The TV uploadTitle is nothing more than a TV with "text" as the input.

            I am display the files in another TV on a page with this for a default value:
            @DIRECTORY /assets/files/newsletters/


            Now, how do I display the TV "Title" for the files?
              • 3722
              • 171 Posts
              ok, I am still having a problem with this.
              Does anyone have any examples on how to do this?
              It seems like there should be something established already that everyone is using.

              I just want to upload a file with a title to a specific folder.

              Any help is appreciated.
              Thanks
              BG66