We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2178
    • 7 Posts
    The following code works on a static site. However, once I try moving it into a snippet in MODx, it no longer is able to return the files (file_exists() returns false). Any suggestions or ideas?

    <?php
    	$url = "some xml doc"; //This is a llink to an XML doc. For security reasons, I can't provide the url.
    
    	if ($fp = fopen($url))
    	{
    		$content='';
    		while($line=fread($fp,1024))
    		{
    			$content .= $line;
    		}
    		$file = fopen("directory.xml", "w");
    		fwrite($file, $content);
    		fclose($file);
    	}
    
    	return null;
    ?>
      • 17422
      • 225 Posts
      hi,

      have you found a solution for this problem, i try to do too but not working.

      Laurent
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Keep in mind that your paths will be relative to the index.php file; every snippet should be treated as a function being called from index.php (or manager/index.php if you’re writing a module).
          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
          • 17422
          • 225 Posts
          ok thanks for your help Susan,

          i want write in a xml files with a module (OnDocFormSave)

          my file is in /assets/fichierXMLMP3/nomfichier.xml;

          in module :

          $fichierXMLMP3=$base_path.’/assets/fichierXMLMP3/nomfichier.xml’;

          my file is not a resource modx.
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            As long as the $base_path variable is set correctly it should work. Have you tried to just echo the full path that it’s generating to make sure it’s correct? Sometimes these things will have an extra / or a missing / which will of course invalidate the path.
              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
              • 17422
              • 225 Posts
              the echo send

              [OnDocFormSave]/assets/fichierXMLMP3/nouvelle_vague.xml

              bizarre smiley

                • 26903
                • 1,336 Posts
                Try ’MODX_BASE_PATH’ .’assets.......................’ or ’$modx->config[’base_path’] .’assets.........’
                  Use MODx, or the cat gets it!
                  • 17422
                  • 225 Posts
                  $fichierXMLMP3=$modx->getOption(’base_path’).’assets/fichierXMLMP3/nouvelle_vague.xml’;

                  work fine

                  thanks for your help

                  Laurent
                    • 3749
                    • 24,544 Posts
                    Quote from: lolotlm at Oct 12, 2010, 02:06 AM


                    in module :
                    $fichierXMLMP3=$base_path.’/assets/fichierXMLMP3/nomfichier.xml’;

                    That should be:

                    $fichierXMLMP3=$base_path . 'assets/fichierXMLMP3/nomfichier.xml';


                    The MODx paths always include a trailing slash.

                      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