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

  • Home
  • SEARCH
  • 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 8648745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:23:07+00:00 2026-06-12T13:23:07+00:00

I have a cron script that needs to write some html into a file.

  • 0

I have a cron script that needs to write some html into a file.

The file that needs to have HTML written is in public_html dir and the script in a different location, just above that dir. If I CHMOD manually everything works, but I don not want to leave it as 0777 or keep on doing it manually, so I wanted to make my script to do it for me.

ob_start();

// build my HTML

$myHTML = ob_get_clean();

// CODE TO SAVE INTO INCLUDE <<<

$filename = 'home/public_html/file.php';

if (is_writable($filename)) {

    if (!$handle = fopen($filename, 'w')) {
         mail("support@domain.com", "Failed to create include", "Script failed to create include", "From: Support <support@domain.com>");
    exit;
    }

    // Write $somecontent to our opened file.
    if (fwrite($handle, ($myHTML)) === FALSE) {
       mail("support@domain.com", "Failed to create include", "Script failed to create include", "From: Support <support@domain.com>");
    exit;
    }

    fclose($handle);

} else {
    mail("support@domain.com", "Failed to create include", "Script failed to create include", "From: Support <support@domain.com>");
    exit;
}

Unfortunately it does not seem to work. Why?

  • 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-12T13:23:08+00:00Added an answer on June 12, 2026 at 1:23 pm

    This looks like an absolute path home/public_html/ are you sure you didn’t mispell it ?
    You can

    var_dump(file_exists($filename))
    

    If true is returned then you can try
    With

    var_dump(file_put_contents($filename,$myHTML))
    

    You can check how much bytes you’ve written in it.
    If false is returned this means you’re having a permission issue

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CRON job php script that I just set up not too
I have a python script that runs on a cron job. The script uses
I have a cron entry that runs a script at a certain time each
If I have a cron job that run every 10 minutes and for some
I have a PHP script that needs to be executed by the end of
I have a php script in my website folder that needs to be executed
We have a cron'ed PHP script that checks an inbox every ten minutes. The
I have a php file that runs as a cron job. That file gets
I have a php script whose name is XYZ.php. When I load that file
I have a PHP script that needs to be run at certain times every

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.