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 288615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:50:00+00:00 2026-05-12T05:50:00+00:00

I am trying to write a file to a sub folder of the directory

  • 0

I am trying to write a file to a sub folder of the directory my cron script is in using file_ put_ contents. However, I keep getting a warning “failed to open stream: No such file or directory.”
I have this directory structure:

httpdocs/scripts/fileDirectory

The cron script lives in the scripts folder. I call it with the cron command:

php httpdocs/scripts/cron_writeFile.php

In the cron_writeFile file, I first tried:

file_put_contents('fileDirectory/', $fileName, $fileContents);

which works when I load the page in a browser, but not when the cron executes.

When I require_once a file in a cron, I have to put the ‘absolute’ path to it:

require_once('httpdocs/scripts/requiredFile.php');

So, I tried that:

file_put_contents('httpdocs/scripts/fileDirectory/', $fileName, $fileContents);

No luck. I’m pretty sure it’s getting to the right folder because the warning is:

“Warning: file_ put_ contents(httpdocs/scripts/fileDirectory/4.txt):
failed to open stream: No such file or directory in
/var/www/vhosts/myDomain.com/httpdocs/scripts/cron_writeFile.php
on line 93”

The both directories have write permissions.

I am using a VPS running (I know it sucks and I need to upgrade, but I don’t have the authority)
Parallels Plesk Panel version 9.2.1
with PHP 5.0.4

The file does not exist and I need a new file each time the script runs.
I am not sure if there is a certain way to define the file path or some other thing I am missing.

Thanks for your help!

  • 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-05-12T05:50:01+00:00Added an answer on May 12, 2026 at 5:50 am

    What if you use dirname(__FILE__) (see) to get an absolute path to your “fileDirectory” directory ?

    Something like this in your script, I guess, if your fileDirectory is a child of the directory where your file resides :

    file_put_contents(dirname(__FILE__) . '/fileDirectory/' . $fileName, $fileContents);
    

    That way, you don’t depend on relative path, which can be wrong if your script is not launched from the “right” directory.

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

Sidebar

Related Questions

I'm trying to write an INI file using the WritePrivateProfileString and WritePrivateProfileStruct functions. I
I'm trying to write an xml file with utf-8 encoded data using ElementTree like
I'm trying to write to a plist file using writeToFile, before I write I
I'm trying to write a script that prints out the file structure starting at
I'm trying to write a file using VBA. My code is below. It worked
Trying to write a python script to extract lines from a file. The file
I'm trying to write a script that will search through a html file and
I'm trying to write a file from an Http post reply to a file
I am trying to write a file to the external storage location on Android.
I'm trying to write a multi-file patch for an open-source project, but the master

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.