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

    Modx 2.2.10
    MySQL : 5.5.32
    PHP : 5.4.19

    I want to create text file with this snippet :

    $parent = $modx->runSnippet('UltimateParent',array('topLevel' => 3));
    $path = 'assets/contenu/docs/bibliographies/biblio'.$parent.'.txt';
    $filename = MODX_BASE_PATH . $path;
    if (file_exists($filename))
    {
    // If File exist, get the content
    return file_get_contents($filename);
    } else {

    // Create file, if the file does not exist
    $fp =fopen($filename,'w');
    fclose($fp);
    };

    The « file_get_contents » is working fine, but the « fopen » does not working.

    I got this message sometimes :
    Parse error: syntax error, unexpected '<' in /home/ceromqcc/public_html/core/cache/includes/elements/modsnippet/70.include.cache.php on line 7

    Something strange with the « fopen », the snippet does not want to save it.

    I have to pass by PhpMyAdmin to write it directly in the database.

    Does anyone ever experience this problem?


    Thank you [ed. note: jber last edited this post 12 years, 10 months ago.]
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Sounds like a mod_security type problem; something doesn't like a form's POST with fopen in it. Usually those will just abort the whole POST process with some kind of server error, though.
        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
        • 13730
        • 149 Posts
        Thank SottWell,

        I will contact my Web Hosting Company, with this problem.
          • 3749
          • 24,544 Posts
          It sounds like you have two problems. The snippet not saving is likely mod_security as Susan suggests. The failure of fopen() is more likely a problem with the permissions or ownership of the directory you're writing the file to.
            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
            • 13730
            • 149 Posts
            Now I can write a file. But I still can not save my snippet with the «fopen»

            I await the response from my Web Hosting Company about this problem. As soon as I have their answer to my problem, I will share it with you.

            Thank
              • 13730
              • 149 Posts
              SottWell was right, it was the mod_security.

              They disabled mod_security et voila! Now I can save my snippet.