We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37523
    • 141 Posts
    I am having troubles with the FileUpload snippet. When I upload a file, the file does not appear anywhere including the directory where I wish the file to be and assets/uploads (the default). No error message appear.

    My call for the snippet is as follows:

    [[!FileUpload?
            &path=`[[+filePath]]`
            &filefields=`1`
            &targetfile=`dave.pdf`
            &maxsize=`2000000`
            &extensions=`pdf`
            &uploadgroups=`uploadGroup`]]


    The [[+filePath]] is coming from my own snippet which contains the following:

    <?php
    $fundSelect= htmlspecialchars($_POST['fundSelect']);
    $fileTypeSelect= htmlspecialchars($_POST['fileTypeSelect']);
    
    $thePath = '../PDF/'.$fundSelect.'/'.$fileTypeSelect.'/';
    $realPath = realpath($thePath);
    $filePath = $realPath.'/';
    
    $modx->setPlaceHolder('fileType',$fileTypeSelect);
    $modx->setPlaceHolder('filePath',$filePath);
    $modx->setPlaceHolder('realPath',$realPath);
    
    return '';


    If I hard code the &path as: /home/helicopterc/PDF/fundName/duedilligence/

    uploads seem to work.

    I have also changed $path (lines 194 and 196 of the FileUpload snippet) to not include the base_path thinking that using a realPath may help to no avail.

    It seems that the [[+filePath]] dynamic part of the snippet call is not being processed correctly. I need this to be resolved as I will also be creating a dynamic &targetfile name.


    Initially I tried defining &path as ../PDF/fundName/duedilligence/. The same problem occurred with using [[+filePath]].

    Looking forward to your help.
    All help greatly appreciated.

    MODX 2.3.1
    PHP 5.4.29
      Glyn Szasz
      Sydney, Australia

      Happy to help (when can) and happy to learn

      If you are a Sydney based MODX developer would love to hear from you. Please contact me.
      • 4172
      • 5,888 Posts
      Did you try to call the placeholder uncached?

      [[!FileUpload?
              &path=`[[!+filePath]]`
              &filefields=`1`
              &targetfile=`dave.pdf`
              &maxsize=`2000000`
              &extensions=`pdf`
              &uploadgroups=`uploadGroup`
      ]]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37523
        • 141 Posts
        Great suggestion Bruno, sadly did not seem to work.

        Quote from: Bruno17 at Aug 22, 2014, 09:12 AM
        Did you try to call the placeholder uncached?

        [[!FileUpload?
                &path=`[[!+filePath]]`
                &filefields=`1`
                &targetfile=`dave.pdf`
                &maxsize=`2000000`
                &extensions=`pdf`
                &uploadgroups=`uploadGroup`
        ]]
          Glyn Szasz
          Sydney, Australia

          Happy to help (when can) and happy to learn

          If you are a Sydney based MODX developer would love to hear from you. Please contact me.
          • 3749
          • 24,544 Posts
          Is your own snippet tag above the FileUpload tag? If not, move it there.

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 37523
            • 141 Posts
            Quote from: BobRay at Aug 22, 2014, 10:51 PM
            Is your own snippet tag above the FileUpload tag? If not, move it there.

            It is. The chunk call with fileUploadSnippet is below. Should I move the snippet to be closer to the FileUpload snippet:

            <h2>[[*pagetitle:ucase]]</h2>
            [[!fileUploadSnippet]]
            <p>Upload a [[+fileType]] file to [[+fundName]]</p>
            <div class="uploadPart">
                [[!FileUpload?
                    &path=`[[!+realPath]]`
                    &filefields=`1`
                    &targetfile=`dave.pdf`
                    &maxsize=`2000000`
                    &extensions=`pdf`
                    &uploadgroups=`KriyaEditor`]]
            </div>
              Glyn Szasz
              Sydney, Australia

              Happy to help (when can) and happy to learn

              If you are a Sydney based MODX developer would love to hear from you. Please contact me.
              • 3749
              • 24,544 Posts
              Ah, you didn't mention that the FileUpload tag was in a chunk. Try moving it up to the page content or the template.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 37523
                • 141 Posts
                Quote from: BobRay at Aug 23, 2014, 03:42 AM
                Ah, you didn't mention that the FileUpload tag was in a chunk. Try moving it up to the page content or the template.
                Tried it.

                So the [[*content]] is now:
                [[!fileUploadSnippet]]
                <p>Upload a [[+fileType]] file to [[+fundName]]</p>
                <div class="uploadPart">
                    [[!FileUpload?
                        &path=`[[!+realPath]]`
                        &filefields=`1`
                        &targetfile=`dave.pdf`
                        &maxsize=`2000000`
                        &extensions=`pdf`
                        &uploadgroups=`KriyaEditor`]]
                </div>


                The entire chunk code (called content_fileupload) that is being called for the page is as follows:

                <h2>[[*pagetitle:ucase]]</h2>
                [[*content]]
                <script type="text/javascript" src="xresource/scripts/jquery-1.10.2.min.js"></script>
                <script type="text/javascript">
                    function deleteImage(file_name) {
                        var r = confirm("Are you sure you want to delete file_name?")
                        if(r == true) {
                            $.ajax({
                              url: 'deleate.php',
                              data: {'file' : "[[+realPath]]/" + file_name },
                              success: function (response) {
                                 // do something
                              },
                              error: function () {
                                 // do something
                              }
                            });
                        }
                    }
                </script>
                
                <div class="existingFiles">
                    <p>RealPath: [[+realPath]]<br>
                    FILEPATH:[[+filePath]]        
                    </p>
                    [[!FileLister?
                	&path=`../PDF/[[+filePath]]`
                	&fileTpl=`CurrentFilesListTPL`
                	&sortBy=`filename`
                	&sortDir=`DESC`
                ]]
                </div>


                This sits within a template of:

                <!DOCTYPE html>
                <html lang="en">
                <head>
                  [[$metaStandard]]	
                </head>
                <body>
                  <div class="wrapper">
                	<div class="header">
                	  [[$LogoBread]]
                	  [[$welcomeLogin]]
                	</div>
                	<div class="content">
                	  <div class="selectlist">[[$content_[[*contentTypeTV]]]]</div>
                	</div>
                	[[showFooter?]]
                  </div>
                [<!-- -->[$Analytics? &trackUser=`[[$trackUserVar?]]`]]
                </body>
                </html>


                The chunk (content_fileupload) is called into the template via the template variable (which is a pop up menu list of defined page types) [[*contentTypeTV]]

                Hope the above makes sense.

                I am starting to think that I may have to skip the entire template variable [[*contentTypeTV]] and build the whole lot as special case template.
                  Glyn Szasz
                  Sydney, Australia

                  Happy to help (when can) and happy to learn

                  If you are a Sydney based MODX developer would love to hear from you. Please contact me.
                  • 3749
                  • 24,544 Posts
                  I don't recall ever seeing a *content tag in a chunk. Normally it's in the page template. FYI, you still don't have the FileUpload snippet tag in the page content or in the template. You have it in a chunk.

                  I think I see what you're doing, but sometimes it's easier just to have multiple Templates (or at least a separate one for pages that will contain a FileUpload snippet tag).

                  This might be relevant (or not): http://bobsguides.com/blog.html/2014/05/15/dont-be-a-nester/.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting