2 Replies - 1557 Views - Last Post: 01 December 2011 - 12:38 PM

#1 black_yurizan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 92
  • Joined: 18-June 11

Reading and Writing files to PHP

Posted 10 November 2011 - 05:11 PM

Hello, I'm reading through tutorials on opening files through php and my question is in one of the modes that is named x. It is suppose to be able to write into a new file or something of that nature. However when I put the x mode into the parameters I get an error message saying "Warning: fopen(welcome.txt) [function.fopen]: failed to open stream: File exists in C:\xampp\htdocs\test.php on line 79". I want to know how I can write into a file and if I'm reading and uploading a file do I have to put the text file in the same directory of the php file?

Here is my code if you want to see it
<div style="border:solid black 1px; width:500px; display:block; margin-bottom:10px;">
$file=fopen("welcome.txt","x") or exit ("Unable to open file");

Is This A Good Question/Topic? 0
  • +

Replies To: Reading and Writing files to PHP

#2 no2pencil  Icon User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6223
  • View blog
  • Posts: 29,815
  • Joined: 10-May 07

Re: Reading and Writing files to PHP

Posted 12 November 2011 - 08:15 PM

According to my tutorial, opening a file with 'x', is requesting read/write file privileges.

Either the file doesn't exist, or the user permissions that your web server service is running under does not meet the required permissions to create a file handle with read & write privileges to welcome.txt.

I would start with checking both of those items.

You should also find the error description in your web server logs. I would assume this to be either IIS or Apache. Whichever it is, I'm sure you can find proper documentation will little effort as to the location of the logs.
Was This Post Helpful? 1
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3988
  • View blog
  • Posts: 12,337
  • Joined: 08-June 10

Re: Reading and Writing files to PHP

Posted 01 December 2011 - 12:38 PM

according to your tutorial, opening an already existing file in "x" mode always fails
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1