By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,474 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,474 IT Pros & Developers. It's quick & easy.

File remains empty

P: 10
Hi, I was trying the following code from a SAMS book. It is supposed to write some output to the purchase.txt file after formatting it through the column application . the file gets created but nothing gets written to it for some reason. Can someone please explain?


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $products = array(
  3.                   array("HAL 2000", 2, "red"),
  4.                   array("Tricorder", 3, "blue"),
  5.                   array("ORAC AI", 1, "pick"),
  6.                   array("Sonic Screwdriver", 1, "orange")
  7.                   );
  8. $handle = popen("column -tc 3 -s / > purchase.txt", "w");
  9. foreach ($products as $p){
  10.     //fputs($handle, join('/', $p). "\n");
  11. }
  12.  
  13. pclose($handle);
  14. echo "done";
  15. ?>
Apr 19 '10 #1
Share this Question
Share on Google+
3 Replies


Atli
Expert 5K+
P: 5,058
Hey.

Have you tried un-commenting line #10?

If yes, try turning on the Debug Messages and see if an error is being suppressed.
Apr 19 '10 #2

P: 10
Oh sorry, that was just a slip, in the real code that line is not commented. Please help...
Apr 19 '10 #3

Atli
Expert 5K+
P: 5,058
Ok.

I'm guessing this is a permission problem. The popen command can not tell whether the column command is actually able to write to the output file, so even if there is a permission problem, odds are that you will see no error.

Try using the is_writable function on the file before trying to write to it, to make sure you have access. If it turns out you don't have access to it, you can try to use the chmod command to alter the access, or log in via FTP (or whatever you use) and change it manually.
Apr 20 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.