Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8914515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:44:27+00:00 2026-06-15T04:44:27+00:00

log_email(email to: . $to . at: . $time); } function log_email($message){ $dir = dirname(__FILE__);

  • 0
    log_email("email to: " . $to . " at: " . $time);
}

function log_email($message){
    $dir = dirname(__FILE__);
    $filename = $dir . "/logs/email_log.txt";       
        echo $filename;

    if(is_readable($filename)){        
        $handle = fopen($filename, "w+");
        $contents = fread($handle, filesize($filename));
        fwrite($handle, $message . "\n" . $contents);
        fclose($handle); 
    }else{
        echo 'The file is not readable.';
    }
}

The file has 777 access, the file contains some text.
I get a warning up saying: Warning: fread(): Length parameter must be greater than 0 in …

$contents variable ends up containing nothing? Any ideas?
The directory must be correct because if i delete the file, my is_readable returns false.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:44:28+00:00Added an answer on June 15, 2026 at 4:44 am

    You are truncating the file when you initially open it with this line.

    $handle = fopen($filename, "w+");
    

    So the size will be zero at that point triggering that warning.

    You should probably do something like this:

    function log_email($message){
        $dir = dirname(__FILE__);
        $filename = $dir . "/logs/email_log.txt";       
            echo $filename;
    
        if(is_readable($filename)){        
            // This will append to the file without destroying its contents
            $handle = fopen($filename, "a+"); 
            fwrite($handle, $message . "\n");
            fclose($handle); 
        }else{
            echo 'The file is not readable.';
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's how my code is structured at the time being: $.post('includes/getPeople.php', {char: character}, function(data)
Using this: function nonce($str,$expires){ return sha1(date('Y-m-d H:i',ceil(time()/$expires)*$expires).$_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT'].$salt.$str); } Let's say I initialize my session_id
I need an advice how to handle function with lots of different return's better.
I'm writing a function for a web app in ASP.NET where the client logs
Apparently I mistyped my email a long time ago, whenever I was setting up
[root@234571-app2 git]# ./test.py File ./test.py, line 4 with open(/home/git/post-receive-email.log,'a') as log_file: ^ SyntaxError: invalid
What would be the best way to get email notifications from error_log errors? For
I use Event log like that: if(!EventLog.SourceExists(Service)) EventLog.CreateEventSource(Service,Sending notification email error); EventLog.WriteEntry(Service, System.String.Format(Sending notification
log.original_fields is always null. why? var updateChangeLog = function(log, currentRecord) { var records, record;
So we all have PHP error logs and we all have to check them.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.