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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:08:23+00:00 2026-05-31T12:08:23+00:00

I am trying to write a simple PHP script that writes a string to

  • 0

I am trying to write a simple PHP script that writes a string to .txt file.
Simple. For that I have this:

<?php
if(isset(isset($_GET["fileName"]) == true && isset($_GET["output"]) == true){
    $fp = fopen($_GET["fileName"], "a+");
    if($fp !== null){
        fputs($fp, $_GET["output"] . "\r\n");
        fclose($fp);
    }
}
?>

But I really need to be able to save to a specific location, so I have written this:

<?php
if(isset($_GET["filePath"]) == true && isset($_GET["fileName"]) == true && isset($_GET["output"]) == true){
    $fp = fopen($_GET["filePath"] . $_GET["fileName"], "a+");
    if($fp !== null){
        fputs($fp, $_GET["output"] . "\r\n");
        fclose($fp);
    }
}
?>

But of course, this doesn’t work.
1. How can I save to a specific location with PHP?
2. Can this path be a relative path? (i just send “/output/” and the save would be done as expected).

Thank you.

Now I am here:

<?php
if(isset($_GET["filePath"]) && isset($_GET["fileName"]) && isset($_GET["output"])){

    $filename=preg_replace('/[^a-z0-9]/i', '', $_GET['fileName']).'.txt';
    $filepathSanitized='http://thepathtomywebsite/~subdomain/'.$_GET["filePath"].$filename;

    echo $filepathSanitized;  // i get the correct path, but no file is present there 
    $fp = fopen($_GET["filepathSanitized"], "a+");
    if($fp !== null){

        fputs($fp, $_GET["output"] . "\r\n");
        fclose($fp);
    }
    else echo ('Something wrong'); // it never gets to this
}
?>

And i am calling the above like this:

$.get("save_me.php", { filePath: "demo/", fileName: "text", output: 'thing to write into' });

But no file is created. I don’t know what to debug to find out what goes wrong.
Thank you.

  • 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-31T12:08:24+00:00Added an answer on May 31, 2026 at 12:08 pm

    But no file is created. I don’t know what to debug to find out what goes wrong. Thank you.

    You should debug the argument that is passed to fopen().

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

Sidebar

Related Questions

I have a simple working PHP script to write an HTML table from a
I'm trying to write a simple php script to take in data from stdin
I have a strange issue. I'm trying to write a simple php webpage on
I have a very simple php ldap script that is only failing when running
I'm currently trying to write a simple script that looks in a folder, and
I'm trying to write a simple PHP script which automatically sets up new etherpads
I'm trying to write up a simple jquery script that parses some JSON and
I'm trying to write a simple PHP MVC framework to play with. Right now,
I am trying to write a simple tool using Shoes. This will indent code
I'm trying to write a simple Vim function that takes the name of a

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.