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

file_put_contents problems

P: 2
Hi, I am very new in this language and I have some problems and I can`t handle it.

Maybe somebody can help me?
file_put_contents and fopen does not work for my and I donīt know what happen :S

1. I need read a random line in a txt hosted in a FTP
2. I need delete this randome line from that txt
3. Next I need put the extracted random line in another txt (not coded yet)

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. /***************************************/
  2. $file = "";
  3. $lines = count(file($file));
  4. $topic = explode("\n", file_get_contents($file));
  5. $random = rand(0,$lines);
  6. $random_topic = $topic[$random];
  8. unset($topic[$random]);
  9. file_put_contents($file, implode('', $topic), LOCK_EX);
  11. /****************************************/
I tried by 2 ways write some files in my host:

file_put_contents($file, "sometext", FILE_APPEND);


$fh = fopen("$file", "w");
fwrite($fh, "sometext");

But those does not work. I put this file 0777 permitions and does not work :S

Someone knows what happening?

PHPversion: 5

Thanks in advance.

Feb 17 '12 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 8,639
what is allow_url_fopen (php.ini) set to?
Feb 18 '12 #2

P: 2
Thanks for your try, I solved it moving all my data to noFTP system, I think that my server block in any way the FTP connections.

Feb 19 '12 #3

Post your reply

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