0

此代码应该将按钮 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>
4

1 回答 1

0

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

$source = '/home/davidsdo/public_html/marknutt/emails/attach/' . $file;
<button onclick="delFunction('<?php echo $source; ?>')" >
于 2012-12-13T14:32:20.663 回答