0

I am trying to write the contents of a variable to a .php file so that I can access that file later, through requite_once, and use that variable later.

The dir that I am trying to write to has 755 permission and I talked to my hosting provider who said that the dir can be written to by me now.

But, the file is not being written. Here is the code that I am trying to write the file with:

error_reporting(-1);
$elasticaObject = var_export($elasticaObject, true);
file_put_contents('theIndex.php', $elasticaObject);
echo "done!";

I get an output of done!done!done!

but, the file is not being written as I get a 404 error when I try to visit it and because it is not-existent in the dir listing.

7
  • 2
    Check the return value of file_put_contents, see if it thinks it is writing anything. It may be writing to a file in a location you are not expecting it as you have not specified a full path to the file.
    – Anigel
    Commented May 9, 2013 at 15:46
  • php.net/file_get_contents - This function returns the number of bytes that were written to the file, or FALSE on failure.. You haven't checked what you got back from the function.
    – N.B.
    Commented May 9, 2013 at 15:47
  • I don't see any error in your code. In addition to the correct file permissions (755) do you have the correct Linux owner and group set for the directory? Must be the same as Apache (or your web server software). Is the PHP file that's doing the writing also at 755 permissions? Commented May 9, 2013 at 15:49
  • @Anigel It is returning (2569).
    – IMUXIxD
    Commented May 9, 2013 at 15:59
  • @IMUXIxD - you need to check where the file is being written - try adding an absolute path to make sure you're writing it where you think it should be.
    – andrewsi
    Commented May 9, 2013 at 16:01

1 Answer 1

1

You must set the write executing permission on the file that contains the script. This is a good guide: http://www.phpjunkyard.com/tutorials/ftp-chmod-tutorial.php

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