fopen failing but no error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rainbowsntoffee
Forum Newbie
Posts: 1
Joined: Thu Aug 28, 2008 3:51 am

fopen failing but no error

Post by rainbowsntoffee »

Hi,
please bear with me as my problem may be glaringly obvious as I am new to this.
Basically I have a super-duper length string (about 50 lines worth) which i need to save to an arbitrary filename.php
This is the code to do that, obviously with the file name stored in $filename

//open file (create if non-existant)
$filename = $name.".php";
$file = fopen($filename, "w+") or die('error file open');
//write back
fwrite($file, $towrite);
fclose($file);
chmod($filename, 0755);

I rough-tested this code on a free host (leadhoster) and after a few mis-starts it worked fine. I then transferred the code to a new host (easily) which is when my problems began.

It doesn't manage to open the file- dies every time. However it doesn't give me an error either.
I thought it might be the die suppressing the error and removed it but nothing happened that time either,
the folder and file both have 0755 permissions.
The folder structure is the same on both hosts.
I've tried with file pre-existing and non-existing,
the phpinfo states the fopen bits are on,
easily run php5.16 by the way.

Can anybody think of a reason why this would not work on the newer server?
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: fopen failing but no error

Post by Ziq »

Try to change error_reporting mode.

Code: Select all

error_reporting(E_ALL);
//open file (create if non-existant)
$filename = $name.".php";
$file = fopen($filename, "w+") or die('error file open');
//write back 
fwrite($file, $towrite);
fclose($file);
chmod($filename, 0755);
 
Any errors?
Post Reply