We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24109
    • 5 Posts
    Hi all,

    I’m at a loss huh I have looked in the forums for a couple of hours and spent more time on the web, but unfortunately haven’t seen anything that helps. My apologies in advance if the solution exists or just simply if this is a silly question.

    Basically, I want to be able to open/create a file, write data to it, and close. I guess you might say I’m trying to write data to a file on a person’s pc. In testing methods to do this, I came up with the snippet:

    <?php
    // Get the data
    include 'assets/templates/write/variables.php';
    // Print the data on the screen
    print $name . " is my name and I am " . $age . " years old.";
    // Set the file
    $SaveLoc = 'C:/Program Files/World of Warcraft/Interface/AddOns/test/DKPInfo.txt';
    // Open or create the file 
    $handle = fopen($SaveLoc, 'w');
     // Write to the data to the file
    fwrite($handle, $name);
    // Close the file 
    fclose($handle);
    ?>
    


    The print $name… was simply to test that the snippet was using the variables I created and functioning on the document I created called “writetest”. When I view the page, I get the following:


    Loretta is my name and I am 27 years old.

    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « PHP Parse Error »

    PHP error debug
    Error: fopen(C:/Program Files/World of Warcraft/Interface/AddOns/test/DKPInfo.txt) [function.fopen]: failed to open stream: No such file or directory


    While it is printing the variables, it of course does not create the file at the destination. I eventually want the code to function with an import/export form.

    Thanks in advance for any guidance.

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You want to write a file to the client PC? You can’t. Web browsers are specifically designed to not be able to do that.

      There are ways to do it in Windows, obviously, or we wouldn’t have so many hacked computers spewing out spam and viruses, but that’s another story altogether, and is a great embarrassment to Microsoft.
        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
        • 24109
        • 5 Posts
        Thank you Susan. I figured as much... I was just mentioning the implications of the script to a friend... shocked I’m new to the language, so that should explain a lot.

        I was trying to help him with a small project he has been working on for gamers. If a user chooses to use his application, they of course will download the zip and install it. Once installed, they will be able to export data from a pc file to the server. We’ve got the export part figured out, but he wants them to be able to import the data also in order to replace/create the data in a file on the users pc (which was part of the initial install). For now, he has the user simply copy the data from the site display and paste it to their file. Any other way to do this, or is the copy/paste method it?

        Also, I understand if the question is no longer appropriate for these forums. Just let me know and I’ll continue looking elsewhere.
        Thank you again for any guidance.

          • 28042 ☆ A M B ☆
          • 24,524 Posts
          This really isn’t a MODx issue, but we’re nice guys wink

          Here’s a lead you can follow... this sort of thing will work in a Windows/IE environment if the client has permissions set in IE to allow it (although I’m not real sure of the exact details, being a Mac user myself)

          http://www.tek-tips.com/viewthread.cfm?qid=1171273&page=1

          You could use a cookie, however...
            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
            • 24109
            • 5 Posts
            Thanks again Susan... much appreciated... I will check out the lead.
              • 19726
              • 239 Posts
              It seems like you wanna update a file from a WoW addon. If so you might want to take a look at UniUploader. It has an option to synchronize Addons with a website. I am not exactly sure how it works, because I only use it to upload data to my website, but it might be worth a look.
                • 24109
                • 5 Posts
                Wow, you guys are like mind readers I swear... I was just looking at ways to possibly synchronize the files... hehe

                Thank you much for the link. I will definately check that out. kiss
                  • 3749
                  • 24,544 Posts
                  A quick and dirty (and not very elegant or bulletproof) way to do what you want might be to simply put a link to the new version of the file on your website and direct the user to click on it, select save, and download it on top of their existing copy of the file.

                  Bob
                    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
                    • 24109
                    • 5 Posts
                    Hi all,

                    For now, the solution has been implemented as BoB mentioned... a simple link to download and update the file.

                    Everyone has been very gracious in providing feedback to this topic even though it did stray from modx topic. Sometimes the forums (not so much at modx) can get harsh when noobs like me post silly questions or unrelated topics.

                    I just want to say thank you. kiss