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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:47:00+00:00 2026-06-05T04:47:00+00:00

I have a php script, that contains some text file writing operation. Now if

  • 0

I have a php script, that contains some text file writing operation. Now if I execute the script from browser, by accessing it using it’s url, it works fine and file is written perfectly. But when I run the same script from terminal, using command, the script runs but no file operation is performed. I am not sure, why this happens. I know it may be a silly thing or I am missing some key or anything but can’t able to figure it out as of now.

Here is the command I am using

/path/to/php -f /path/to/file

Here is the code which writes to text file:

$myFile = "filename.txt";
$fh = fopen($myFile, 'a+') or die("can't open file");
$str = "file content here";
fwrite($fh, $str);
fclose($fh);

Thanks for the 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-06-05T04:47:02+00:00Added an answer on June 5, 2026 at 4:47 am

    This may be using different paths. For example, when run from the terminal it will be looking for “filename.txt” in the directory you are in when you run the command, whereas when running from the browser it will look in the same directory as your PHP file.

    To fix this use the full path rather than just the filename for the file you are accessing.

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

Sidebar

Related Questions

I have a PHP script that executes a .bat file using system(cmd /c C:\dir\file.bat);
I have some problems with a PHP script that calls a Bash script.... in
I have multiple Controller objects that either execute some script and then redirect to
I have a PHP script that doesn't seem to work when it contains a
I have a PHP script that is using wget to download some images. However,
I have a page that contains some JS to update the browser history (
I have a php script that is waiting for ajax calls at www.mydomain.com/file.php The
I have the following php script that allows me perform some calls to other
I have php script that creates a temporary watermark image for users that are
I have a php script that backup my table in .sql format and I

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.