473,396 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Weird Troubles Writing to File

I'm trying to use PHP to create a text file. Simple right? I've done
it before. I don't know why it's not working now. It's not rocket
science. In general, I'd say I'm a PHP beginner, but with an
intermediate skill level in certain facets of the language.

$thisFileName = 'test.txt';
$fp = fopen($thisFileName, "w");
$write = fputs($fp, "test");
fclose($fp);
if (!file_exists($thisFileName))
die("File does not exist.");

* This script is in the same directory as the text file.
* I am on a Windows server.
* The permissions for the folder I'm in, and the files, is 666
(read/write).
* I have tried using just the file name and also the full path.

I can modify that script to do a READ instead of a write, and set the
filename to a file that exists already.... it works just fine. But
even if I leave the filename to a file that exists, and try the above
script to write over it... it won't work.

How can I find out what the problem is? I'm not getting any PHP error
info on browser. I guess they have debugging turned off.

Thanks for any help!

--
JGG

May 5 '06 #1
2 1235

Jolly Green Giant wrote:
I'm trying to use PHP to create a text file. Simple right? I've done
it before. I don't know why it's not working now. It's not rocket
science. In general, I'd say I'm a PHP beginner, but with an
intermediate skill level in certain facets of the language.

$thisFileName = 'test.txt';
$fp = fopen($thisFileName, "w");
$write = fputs($fp, "test");
fclose($fp);
if (!file_exists($thisFileName))
die("File does not exist.");

* This script is in the same directory as the text file.
* I am on a Windows server.
* The permissions for the folder I'm in, and the files, is 666
(read/write).
* I have tried using just the file name and also the full path.

I can modify that script to do a READ instead of a write, and set the
filename to a file that exists already.... it works just fine. But
even if I leave the filename to a file that exists, and try the above
script to write over it... it won't work.

How can I find out what the problem is? I'm not getting any PHP error
info on browser. I guess they have debugging turned off.

Thanks for any help!

--
JGG


Sorry, not sure what the problem is.

You should be able to turn error messages on with error_reporting(),
use

error_reporting(E_ALL);

Another thing you could try is cut n paste the script in the php manual
for fwrite (its identical to fputs) as it checks for errors after each
step and it might tell you where the problem is.
http://www.php.net/manual/en/function.fwrite.php

Seeya

Tim

May 5 '06 #2
Thank you! That error_reporting changed the debugging so that it told
me that my file perms were wrong. Perfect. Thank you

May 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Wolfgang Kaml | last post by:
Hello All, I have been researching newsgroups and knowledgebase all morning and not found a solution that would solve the problem I have. I am having an ASP or ASPX web page that implement a...
11
by: HelLind | last post by:
Hello people, I am having a weird error and don't know what term to search in google. Sorry to bother. There is data in my field "M_BIO" When I run this code...
7
by: Francois | last post by:
Salut - Hello, I'm trying to comply with W3C HTML 4.01 Strict standards BUT one JS code is causing me troubles. The parser returns an error of "having a closure tag </a> with no other tag open...
9
by: Kelly Vernon | last post by:
I have a standard ASP page that appends to an xml page. Currently if there is more than one person attempting to append to the same XML file at a time. One user will have the ability to append,...
1
by: Eddie Fisher | last post by:
Hello, I am new to this newsgroup. I came here looking for help on an odd error: I am currently attempting to make a program that tracks statistics . It is supposed to write and read objects...
4
by: James Aguilar | last post by:
Take the following code example: class Array { double *m_array; public: Array() { m_array = new double; } double *begin() const {return m_array;} }; int main() {
4
by: phantom | last post by:
Hi All. I am having a problem writing to a file. I can successfully open the file and write the contents using fprintf, however if the writing is not done for a while in the process the file...
2
by: Joe324 | last post by:
Hello, I'm writing a program that will (eventually) read in a list of names from a file and store them in a linked list. I have the basics of the program done and it compiles with no errors, but...
4
by: spiralfire | last post by:
I wrote a translator, that reads a DIMACS graph format and writes to a simpler format... basically DIMACS format is: c comment p type nodes edges //type is alwats edge on my problems,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.