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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:40:59+00:00 2026-06-15T18:40:59+00:00

I am passing variables from a button into a myFunction. I can create an

  • 0

I am passing variables from a button into a myFunction. I can create an alert box showing the correct information but when I use these variables in a copy command it does nothing. My goal is to display images in a directory. The user can click on the button with that image in it and have it copy the image file from the /storage/ directory to the /attach/ directory. Can anyone help me with this please….Thanks

My complete file i’ve created is:

<!DOCTYPE html>
<html>
<head>
<title>Mark Nutt</title>
<script>
 function myFunction(greeting,greeting2,source,destination)
 {
<?php
    echo copy('"+source+"','"+destination+"');
?> 
    alert("copy('"+source+"','"+destination+"')");
    alert(greeting2 +' attached to email!');
    }
 </script>
</head>
<body>
<a href="#" onclick="MyWindow=window.open('http://www.davidsdomaindesign.com/marknutt/emails/emails.php','_self'); return true;"><font size="2" color="white"><input type="button" value="I'm Done" /></font></a><br />
<?php
 $files = glob("/home/davidsdo/public_html/marknutt/photos/storage/*.jpg");
 asort($files);
 for ($i=0; $i<count($files); $i++)
 {$num = $files[$i];
  $file = substr($num,51);
?>
<button onclick="myFunction('<?php echo $file ?>','<?php echo substr_replace($file,"",-4); ?>','<?php echo $source='/home/davidsdo/public_html/marknutt/photos/storage/'; echo $file; ?>','<?php echo $destination='/home/davidsdo/public_html/marknutt/emails/attach/'; echo $file; ?>')" >
<input type="button" value="<?php echo substr_replace($file,"",-4); ?>" /><br /><img src="http://www.davidsdomaindesign.com/marknutt/photos/storage/<?php echo $file ?>" alt="<?php echo $file ?>" width="125" height="125">
</button>
<?php
 }
?>
</body>
</html>
  • 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-15T18:41:00+00:00Added an answer on June 15, 2026 at 6:41 pm

    You can not use javascript variable on php code.
    You should use a php function to do it.
    use this code insted:

    <!DOCTYPE html>
    <html>
    <head>
    <title>Mark Nutt</title>
    <script>
    function myFunction(greeting,greeting2,source,destination)
    {
    window.location = "?greeting="+greeting+"&greeting2="+greeting2+"&source="+source+"&destination="+destination;
    }
    </script>
    
    <?php
    ////////////////////////////////////
    if(isset($_GET['greeting'])){
       if(copy($_GET['source'],$_GET['destination'])){
          echo '<script language="javascript">';
          echo "alert('copy({$_GET['source']},{$_GET['destination']})');";
          echo "alert('{$_GET['greeting2']} attached to email!');";
          echo'</script>';
       }
    
    }
    ?>
    </head>
    <body>
    <a href="#" onclick="MyWindow=window.open('http://www.davidsdomaindesign.com/marknutt/emails/emails.php','_self'); return true;"><font size="2" color="white"><input type="button" value="I'm Done" /></font></a><br />
    <?php
     $files = glob("/home/davidsdo/public_html/marknutt/photos/storage/*.jpg");
     asort($files);
     for ($i=0; $i<count($files); $i++)
     {$num = $files[$i];
      $file = substr($num,51);
    ?>
    <button onclick="myFunction('<?php echo $file ?>','<?php echo substr_replace($file,"",-4); ?>','<?php echo $source='/home/davidsdo/public_html/marknutt/photos/storage/'; echo $file; ?>','<?php echo $destination='/home/davidsdo/public_html/marknutt/emails/attach/'; echo $file; ?>')" >
    <input type="button" value="<?php echo substr_replace($file,"",-4); ?>" /><br /><img src="http://www.davidsdomaindesign.com/marknutt/photos/storage/<?php echo $file ?>" alt="<?php echo $file ?>" width="125" height="125">
    </button>
    <?php
     }
    ?>
    </body>
    </html>
    

    to delete you can use this:

    <script>
    function delFunction(source)
    {
        window.location = "?delete="+source;
    }
    </script>
    <?php
    if(isset($_GET['delete']){
        unlink($_GET['source']);
    }
    ?>
    

    but I prefer to move file to other directory instead of remove it(to log that who want to delete file) or use db to manage images.

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

Sidebar

Related Questions

Looking to pass variables from c# to javascript to use some jquery code. Passing
I'm having some interesting issues with passing in variables from within an object into
I was recently pointed to gon for passing variables from my controller to javascripts
Question: I am having issues passing session variables from parent page to iFrame page
My instructions are to call a function when passing variables into an insert statement
I have this code below. As you can see I am passing two variables
Possible Duplicate: passing variables from php to javascript I am using this awesome jQuery
Hi i'm trying to retrieve response after passing some variables from javascript to php
I have read various articles about passing variables around using RMI. Some of them
I have a problem with passing variables as reference in PHP. I want to

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.