rainbowsntoffee Posted August 28, 2008 Share Posted August 28, 2008 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? Link to comment https://forums.phpfreaks.com/topic/121668-fopen-failing-but-no-error/ Share on other sites More sharing options...
JasonLewis Posted August 28, 2008 Share Posted August 28, 2008 Nothing springs to mind. You can add error_reporting(E_ALL); at the top of your page, see if any errors are outputted. Link to comment https://forums.phpfreaks.com/topic/121668-fopen-failing-but-no-error/#findComment-627675 Share on other sites More sharing options...
kratsg Posted August 28, 2008 Share Posted August 28, 2008 Add this line in respectively... it may be that you're opening it (hence no die error) but it's just not writing it. fwrite($file, $towrite) or die('file write error'); Link to comment https://forums.phpfreaks.com/topic/121668-fopen-failing-but-no-error/#findComment-627679 Share on other sites More sharing options...
rainbowsntoffee Posted August 28, 2008 Author Share Posted August 28, 2008 ProjectFear - Sorry, I forgot to mention that I already tried the error_reporting(E_ALL) line. No errors/warnings/anything else are displayed. kratsg, I maybe didn't write that clearly enough (Sorry again!) but it does give me the die error, just obviously thats not an explanation of why it has decided to hate me I'd sign up to the posher version of the original host but now its sort of personal, you know? I've been swearing at the stupid thing for the best part of two weeks.. Link to comment https://forums.phpfreaks.com/topic/121668-fopen-failing-but-no-error/#findComment-627732 Share on other sites More sharing options...
PFMaBiSmAd Posted August 28, 2008 Share Posted August 28, 2008 Put both these lines immediately after your <?php tag - ini_set ("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/121668-fopen-failing-but-no-error/#findComment-627741 Share on other sites More sharing options...
rainbowsntoffee Posted August 28, 2008 Author Share Posted August 28, 2008 oh wow! errors! Thanks PFMaBiSmAd Warning: fopen(/home/.sites/20/site458/web/includes/new.php) [function.fopen]: failed to open stream: Permission denied in /home/.sites/20/site458/web/updatemainf.php on line 297 The script using fopen is in the web folder. I've tried: new.php /includes/new.php include/new.php obviously, the whole lot as above, http://the address for it all The web folder is set to 777 permissions, the includes to 755. I'm guessing it's something in the settings. What am I looking for? the obvious setting including fopen is set to on, which I presume is a good thing? Help please! Link to comment https://forums.phpfreaks.com/topic/121668-fopen-failing-but-no-error/#findComment-627849 Share on other sites More sharing options...
discomatt Posted August 28, 2008 Share Posted August 28, 2008 The folder AND the file must be 777, unless PHP creates the file itself. Link to comment https://forums.phpfreaks.com/topic/121668-fopen-failing-but-no-error/#findComment-627856 Share on other sites More sharing options...
rainbowsntoffee Posted August 28, 2008 Author Share Posted August 28, 2008 php creates the file. Link to comment https://forums.phpfreaks.com/topic/121668-fopen-failing-but-no-error/#findComment-627875 Share on other sites More sharing options...
discomatt Posted August 28, 2008 Share Posted August 28, 2008 Weird, you'd figure the server would give write permissions to the user that initially creates the file. Try CHMOD'ing the file 777 anyways? Link to comment https://forums.phpfreaks.com/topic/121668-fopen-failing-but-no-error/#findComment-627892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.