473,799 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem Writing To File

Hello all.

Okay, this seems really stupid, but it's driving me up the wall.

I have a simple script I've written to log some information to a text
file. Everything seems to be okay, the code isn't throwing any errors,
but for some reason it isn't writing to file. If anyone has any ideas,
please let me know.

Here's the code I'm using:

//trigger_error(" Just Testing to see if this is working",E_USER _NOTICE);
$strTimeStamp=d ate("F j, Y h:i:s A");
$strLogEntry=$s trTimeStamp . ", " . $REQUEST_URI . ", " . $_SERVER
['HTTP_REFERER']. "\r\n";
//echo $strLogEntry;
$logfile='../logs/fce.log';

$logExists=file _exists($logfil e);
if($logExists){
echo "File Exists<br>";
}
else{
echo "File Does Not Exist<br>";
}

$writable=is_wr itable($logfile );
if($writable){
echo "File Can Be Written to<br>";
}
else{
echo "File Cannot Be Written to<br>";
}

$fileHandle=fop en($logfile, "a");

if($fileHandle) {
echo "File Opened for writing.<br>";
$written=fwrite ($fileHandle, $strLogEntry);
echo "File written to successfully.<b r>";
$closed=fclose( $fileHandle);
echo "File closed succesfully.<br >";

}
else{
error_log("$log file does not exist");
}

--
Randy Jackson
http://fourcolorexplosion.com
Jul 17 '05 #1
2 2218
["Followup-To:" header set to comp.lang.php.]
Randy Jackson wrote:
I have a simple script I've written to log some information to a text
file. Everything seems to be okay, the code isn't throwing any errors,
but for some reason it isn't writing to file. If anyone has any ideas,
please let me know.
Turn on error reporting if you don't already have it.

Put these at the top of your scripts
<?php
error_reporting (E_ALL);
ini_set('displa y_errors', '1');
?>

or change php.ini to have it on at all times.
Here's the code I'm using:

//trigger_error(" Just Testing to see if this is working",E_USER _NOTICE);
$strTimeStamp=d ate("F j, Y h:i:s A");
$strLogEntry=$s trTimeStamp . ", " . $REQUEST_URI . ", " . $_SERVER ^^^^^^^^^^^^
Not that it matters for the problem at hand,
but do you have "register globals" on?
['HTTP_REFERER']. "\r\n"; ^^^^^^
Shouldn't this be only "\n" and let the OS do the translation?
Again, it doesn't matter for your problem :-)

[snip] $fileHandle=fop en($logfile, "a"); ^^^
text-mode translation; use "ab" for binary-mode.
if($fileHandle) {
echo "File Opened for writing.<br>";
$written=fwrite ($fileHandle, $strLogEntry);
if ($written === false) echo "ERROR: Could not write to file.<br>";
else {
echo "wrote $written bytes to file -- expected to write ";
echo strlen($strLogE ntry), ".<br>";
}
echo "File written to successfully.<b r>";
$closed=fclose( $fileHandle);
echo "File closed succesfully.<br >";

}
else{
error_log("$log file does not exist");
}


Happy Bug Hunting :-)
--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |
Jul 17 '05 #2
On Fri, 29 Oct 2004 16:53:58 -0500 (more or less), Randy Jackson
<ra**********@n ounsolicitedfou rcolorexplosion .com> wrote:
Hello all.

Okay, this seems really stupid, but it's driving me up the wall.

I have a simple script I've written to log some information to a text
file. Everything seems to be okay, the code isn't throwing any errors,
but for some reason it isn't writing to file. If anyone has any ideas,
please let me know.

Here's the code I'm using:


Your code worked for me! I did have to add <? to the beginning and ?> to the
end, but that was it. The contents of fce.log are "October 30, 2004 09:08:13
AM, , ". Make sure you have create and write permissions in the logs
directory for the user id of your httpd daemon.
Jul 17 '05 #3

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

Similar topics

2
1352
by: Pierre Rouleau | last post by:
Hi all! I'm trying to extend the functionality of the file object by creating a class that derives from file. MyFile class re-implements __init__(), write(), writelines() and close() to augment the capabilities of file. All works fine, except for one thing: 'print >> myfile' does not execute Myfile.write(), it executes the file.write(). If I execute myfile.write() explicitly, then Myfile.write() is called as expected.
8
9859
by: Brandon McCombs | last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm trying here. I have a C++ book by Deitel and Deitel that says I can use fstream File("data.dat", ios::in | ios::out | ios::binary) to declare a file object with read/write modes turned on for working with binary data. I've tried this and my file is not created. The only time it is created is when I specify ifstream or ofstream but not fstream. I've tried removing the...
25
7756
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30 minutes with Python 3 times a week since, have 14 years of computing experience, 8 years in mathematical computing and 4 years in unix admin and perl, i have quickly found the official doc: http://python.org/doc/2.4.1/lib/module-gzip.html
0
3944
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
6
5276
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
0
2023
by: deacon57 | last post by:
FYI - If you are a computer scientist (or geek), this post may be for you. I wanted to log any search keywords, etc that are used on my site. I created a simple program that logs search terms into a log file. The problem I experienced was that I was getting double entries in the log... that is, when writing to the file, each line I wrote to the file was repeated twice. How was that possible? Scanning the code provided no clues. The PHP...
2
3112
by: Thelonious Monk | last post by:
I have a problem where some data is being eliminated. The problem is that the data contains signed numeric fields (the low-order byte of a negative number uses the first 4 bits as a sign and the last 4 bits as the low-order digit. This produces byte values higher than X'7F'. To be more specific these values are hexadecimal X'B0' through X'B9'. It appears the program is eliminating any byte values greater than X'7F', thus shortening...
10
2289
by: Rahul | last post by:
Friends, My Problem is related to writing a text file from a database using .Net. in a particular string format. I have a dataset with a table, let suppose in this table there are three fields. - Code - Description - Amount
5
5169
by: Neil Crighton | last post by:
I'm using the zipfile library to read a zip file in Windows, and it seems to be adding too many newlines to extracted files. I've found that for extracted text-encoded files, removing all instances of '\r' in the extracted file seems to fix the problem, but I can't find an easy solution for binary files. The code I'm using is something like: from zipfile import Zipfile z = Zipfile(open('zippedfile.zip'))
0
9686
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9540
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10475
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10250
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10222
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.