将变量从按钮传递到同一文件中的js

时间:2012-12-13 14:27:56

标签: php unlink

此代码应该将按钮delFunction中的变量传递给delFunction脚本,并删除与该按钮关联的文件。它没有传递变量。我在脚本下面插入了两个警告语句,它们在结果页面上显示为命令中没有变量名称的文本。我搜索了stackoverflow,我尝试过的每一项技术都没有用。请帮忙......大卫

<!DOCTYPE html>
<html>
<head>
<title>Mark Nutt</title>
<script>
function delFunction(source)
{
    window.location = "?source="+source;
}
</script>
<?php
////////////////////////////////////
      echo "alert('copy({$_GET['source']},{$_GET['source']})');";
      echo "alert('unlink({$_GET['source']})');";
if(isset($_GET['source'])){
   if(unlink($_GET['source'])){
      echo '<script language="javascript">';
      echo "alert('{$_GET['source']} detached from 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/emails/attach/*.*");
 asort($files);
 for ($i=0; $i<count($files); $i++)
 {$num = $files[$i];
  $file = substr($num,50);
?>
<button onclick="delFunction('<?php echo $source='/home/davidsdo/public_html/marknutt/emails/attach/'; echo $file; ?>')" >
<input type="button" value="<?php echo $file ?>" /><br /><img src="http://www.davidsdomaindesign.com/marknutt/emails/attach/<?php echo $file ?>" alt="<?php echo $file ?>" width="125" height="125">
</button>
<?php
 }
?>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

不要在echo语句中设置变量,而是尝试将按钮的定义更改为此。

$source = '/home/davidsdo/public_html/marknutt/emails/attach/' . $file;
<button onclick="delFunction('<?php echo $source; ?>')" >