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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:26:10+00:00 2026-06-16T20:26:10+00:00

I want to build a one page utility/prototype that will do the following: provide

  • 0

I want to build a one page utility/prototype that will do the following:

provide the admin user with a drop down box. when they select an option and then click on a submit button, i want to be able to COPY a file from /var/www/mysite/abc.txt to /var/www/mysecondsite/abc.txt

I’ve written the php / html to display the form, but can I use jquery/ajax to call a function on the same php file?

Here’s my code:

<?php

$listofcountries='';

echo "<h2>Select a site</h2>";
echo " <script src='http://myserver/myapp/assets/js/jquery-1.8.1.min.js'></script>";

if ($handle = opendir(dirname(__FILE__)."/secrets/")) {

  echo "<input type=text list=site >";
  echo "<datalist id=site >";

    /* This is the correct way to loop over the directory. */
    while (false !== ($entry = readdir($handle))) {
    //ignore temporary files, and directories.
    if ( (strpos($entry, "~") === false) && !(trim($entry)==".") && !( $entry=="..") ){
          //echo "$entry\n<BR>";
          $country=getCountryName($entry);
          echo "<option>".$country;
      }
    }
    }
    closedir($handle);

echo "</datalist>";
echo "<input type=submit id='changert'><BR>";
echo "<script>";
echo "$(document).ready(function(){";

echo "       $('#changert').live('click', function()  {";
echo "      alert('in the changert function'); ";
echo "      });";

echo "  }); "; //end document ready
echo "</script> "; //end javascript



function getCountryName($fileame)
{
    $pattern = '/([a-z]*).([a-z]*).([a-z]*).php/i';
    preg_match_all($pattern, $fileame, $matches, PREG_SET_ORDER);           
    foreach ($matches as $match) {

        return $match[1];
    }
}

in the real version, this solution will be part of a codeigniter solution… so i’ll have a proper MVC.
But for now, I’d like to be able to contain all the logic in one file.
Can you tell me how i can do this?

  • 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-16T20:26:11+00:00Added an answer on June 16, 2026 at 8:26 pm

    jQuery is just JavaScript so it’s all on the client. Any server-side file copying would still need to be handled by your PHP. Simplest solution is just to make an AJAX request on button click which hits your PHP API and passes a token or something so non-session users aren’t copying files maliciously.

    $('#myButton').on('click', function(e) {
    
        $.ajax({
            url  : '/copyFile.php',
            data : {
                fileName : $('#mySelectMenu').val(),
                token    : someTokenYourPHPInjectedIntoYourJS
            },
            type : 'POST',
            success : function (data) {
                // yay
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to build a page that user can drag & drop images over
I want to build a site that will ask if the user is male
I want to create a one page site that will use Facebook Connect and
I have a website project that I want to build using CruiseControl.net. On one
I want to build flash application that can detect the user eyes color and
I want to build a form_tag that will allow me to post a new
I want to build a dynamic navigation menu that will fill in automatically based
I want to build a website similar with tumblr homepage. On that page, while
I want to build a bookmarklet that will allow me to send the URL
Well the title is quite self explanatory. I want to build two panels one

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.