1

I need to write file by pushing retrieved data in to text file. But the file not write. This is the relevant code section. This code section contains within function in controller.

            $filename = "form_ipn.log";
            $fh = fopen($filename, "a") or die("Could not open log file.");
            fwrite($fh, date("d-m-Y, H:i")." - $name;\n") or die("Could not write file!");
            fclose($fh);

I have created a file inside a controller->adminhtmlfolder. Is there any problem with this folder regarding writing privileges? Or is there any problem on my code?

6
  • 1
    Direct file functions are not recommended in Magento. If you are just after some logging, try Mage::log instead.
    – Prateek
    Commented Feb 29, 2016 at 6:33
  • 1
    yes might be privileges issue as you have not mentioned path of file so it will be default to controller->adminhtml folder. and follow @Prateek's comment as well Commented Feb 29, 2016 at 6:36
  • 1
    Yo can specify by like Mage::getBaseDir('media'), Mage::getBaseDir('var'); Commented Feb 29, 2016 at 6:44
  • 2
    For example $filename = Mage::getBaseDir('media').DS."form_ipn.log"; it will write your file in media folder on root Commented Feb 29, 2016 at 6:46
  • 1
    @MineshPatel Yeah. It works in media folder. Thanks.
    – Dis_Pro
    Commented Feb 29, 2016 at 6:58

1 Answer 1

2

Converting comments to answer

yes might be privileges issue as you have not mentioned path of file so it will be default to controller->adminhtml folder

Yo can specify by like

Mage::getBaseDir('media'), Mage::getBaseDir('var');

For example $filename = Mage::getBaseDir('media').DS."form_ipn.log"; it will write your file in media folder on root

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.