We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38255
    • 8 Posts
    I'm using Revo 2.2pl2 and FileUpload 1.0.1rc1.
    The task is to upload some images from frontend and preview them on the same page.
    Here (Russian only) is a good example of using AJAX with MODx, so the preview seems to me a bit easier part of the task. But for using any ways to show images, first I need the path, do I?
    So there are my questions:
    1) is there any way to get paths of recently uploaded files without re-engineering FileUpload snippet, for example, to some placeholders;
    2) how to get uploaded files renamed before they are got to the directory, once again, without refactoring of FileUpload?

    P.S. I'm only new-newby with php and modx, so be patient, please smiley
      • 38255
      • 8 Posts
      There're some thoughts of answering first question, but in my case I need to rebuilt FileUpload and do some php-tricks there, and I'm a bit concerned about my php-skills.
      I suspect some extra must be added here, in 235 line:
            //Handle the uploaded file
            $uploadfile = $path.basename($_FILES['userfile']['name'][$i]);
      
        • 3749
        • 24,544 Posts
        There's really no easy way to do it without modifying the FileUpload snippet. It's a quick-and-dirty port of an Evolution snippet and it doesn't set any placeholders at present.

        The line numbers will be a little off in the following because I have a newer version that hasn't been released yet.

        If you find this line in the code (around line 262):

        $fileoutput = $modx->lexicon('fu_uploaded');


        That's where the message is set when the file has been successfully uploaded. $fileoutput is set to the fu_uploaded language string there, so I think you could just edit that language string to contain some HTML and a placeholder for the path, then use str_replace right there to inject the path. The path is available there as $sp['path'] (assuming that you set that property). It's kind of a goofy method, but I think it would work. Be sure to back up the language file before upgrading, because it will get overwritten.

        Just above that point, you'll see a move_uploaded_file() call which you could use to rename the file.

        If I have time someday, I'll refactor the thing to use a proper Tpl for a success message and set some placeholders.

        Hope that helps.

        ---------------------------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
        MODX info for everyone: http://bobsguides.com/modx.html
        [ed. note: BobRay last edited this post 14 years, 6 months ago.]
          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