1

I'm following a tutorial on php, and am having difficulty getting this to work. I set the appropriate directory permissions to read and write, but every time I run this, I get the die string.

The code is:

$ourFileName = "testFile.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);

As far as my basic understanding goes, if "testFile.txt" does not exist, fopen should create that file (I have basic knowledge of Python, and remember this same principle in that language). But it...it doesn't. Even if I create the aforementioned file, and put it up, that line of code still returns a die string.

My hosting account does not give me permission to execute. Is this a problem?

My server runs on Windows. I am using Dreamweaver CS5, on OSX 10.5.8.

I've done some searching on this, and see other people having similar issues - but none of them keyed to exactly my range of problems. Being that I'm a beginner, I feel that it might be something I'm overlooking.

Thanks!!

  • 2
    Remove the or die("can't open file"); and see what error/warning fopen throwing – Shakti Singh Jan 03 '11 at 07:13
  • Unless you for some reason want to display your own errormessage when this fails I support Shakti in not using or die, as the standard errormessages will (almost) always be more helpful – Sondre Jan 03 '11 at 07:19
  • 1
    @Shakti this die operator do not suppress any error messages. So, removing it will help nothing – Your Common Sense Jan 03 '11 at 08:42

2 Answers2

1

The 'or die' doesnt really do much for you other than killing the script...

Seeing as your code should work... Try debugging:

Put this at the top of your php

error_reporting(E_ALL); 
ini_set('display_errors','1'); 
CarpeNoctumDC
  • 1,760
  • 1
  • 12
  • 16
0

Problem fixed. I use godaddy, and had them switch my account - which was previously housed on a Windows server - over to a Linux one. With Windows, I didn't have as much control over file permissions. Now I do - and now that code works as it should.