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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:12:38+00:00 2026-05-24T02:12:38+00:00

I have the following code in my index.php page: // Write the resulting JSON

  • 0

I have the following code in my index.php page:

// Write the resulting JSON to a text file
    var jsontext = $('#code-output').text();
    $.ajax({
      url: 'writetxt.php',
      type: 'POST',
      data: { data: jsontext },
      success: function(result) {
        $('#code-output').hide().fadeIn('slow');
      }
});

And this is the contents of writetxt.php:

// Generating a unique filename using the date and time plus a random 4-digit string
$filename = date("YmdHis-") . rand(1337,9001);

// Making the JSON text file
$jsontext = $_POST["data"];
$fp = fopen("jsontxt/" . $filename . ".txt","w");
fwrite($fp,$jsontext);
fclose($fp);

Basically, a new text file is created every time a change is made to the JSON text. How do I access $filename from the index.php file?

  • 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-24T02:12:38+00:00Added an answer on May 24, 2026 at 2:12 am

    Either include the file in the other one

    require_once('my_file.php');
    
    echo $varFrom_my_file;
    

    or set it to a session variable

    session_start();
    
    $_SESSION['foo'] = "Bar";
    

    Then the other file

    echo $_SESSION['foo'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code inside the body of my index.php page: echo Begin
I have currently the following code: <li><a href=index.php id=1 onclick=document.getElementById('1').style.background = '#8B4513';>Weblog</a></li> This changes
I have a menu using the following code, <ol id=feature_list> <li><a href=index.php?action=profile class=feature_current>Profile</a></li> <li><a
I have placed the following code at the top of index.php: if (!isset($_SERVER['REMOTE_ADDR'])){ $_SERVER['QUERY_STRING']
I am using wordpress and on the page sidebar.php I have the following code:
In a php page I have following code: if($_REQUEST['c']!=) // I get error on
I have the following code in my Ajax, which executes a page reload function
When a visitor goes to a index.php file the following code is run. There
i have this URI. http://localhost/index.php?properties&status=av&page=1 i am fetching basename of the URI using following
I have the following code in my main index.php: <div class=form> <?php $oForm =

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.