[英]How to call a PHP function in an HTML form as an action to an attachment
我有一个html表单,我有一个php函数。 我需要html表单中的attachment元素来运行php函数代码,然后将其发送到电子邮件。 我需要对数据进行解析,然后将其发送到电子邮件。 附件将是SPA扩展名。
这是表格的代码-
<form METHOD = "POST" action="mailto: abc@xyz.com">
Material :
<input type ="text" name="material number"/> <br>
Batch Number:
<input type ="text" name= "batch number"/ > <br>
Processing Stage:
<input type ="text" name= "Processing State"/ > <br>
Analysis:
<input type= "text" name= "Analysis" /> <br>
Attachment:
<METHOD="post" ACTION="generatePlotForSPA(attachedfile)" ENCTYPE="multipart/form-data">
<INPUT TYPE="file" NAME="attachedfile" MAXLENGTH=5000 > <br>
<input type="submit" value="Submit"/> <br>
</form>
这是PHP代码-
<?php
function generatePlotForSPA($source, $targetFile) {
$sourceFile = fopen($source, "rb");
fseek($sourceFile, 386);
$targetOffset = current(unpack("v", fread($sourceFile, 2)));
if($targetOffset > filesize($source)) {
return false;
}
fseek($sourceFile, 390);
$dataLength = current(unpack("v", fread($sourceFile, 2)));
if($dataLength + $targetOffset > filesize($source)) {
return false;
}
fseek($sourceFile, $targetOffset);
$rawData = fread($sourceFile, $dataLength);
$rawDataOutputPath = $source . "_raw_data";
$outputFile = fopen($rawDataOutputPath, "w");
fwrite($outputFile, $rawData);
fclose($outputFile);
$gnuScript = "set terminal png size {width},{height};
set output '{output}';
unset key;
unset border;
plot '<cat' binary filetype=bin format='%float32' endian=little array=1:0 with lines lt rgb 'black';";
$targetScript = str_replace("{output}", $targetFile, $gnuScript);
$targetScript = str_replace("{width}", 500, $targetScript);
$targetScript = str_replace("{height}", 400, $targetScript);
$gnuPath = "gnuplot";
$outputScript = "cat \"" . $rawDataOutputPath . "\" | " . $gnuPath . " -e \"" . $targetScript . "\"";
exec($outputScript);
if(!file_exists($targetFile)) {
return false;
}
return true;
}
?>
关于如何连接两者的任何建议
您需要在action="the_php_file.php"
调用php文件
然后将要采取行动的邮件包含在文件本身中
html形式动作中的函数调用是面向对象的php的功能。 您不能在原始php中使用它。
首先创建2个文件1-something.php 2-processing.php
比在something.php中形成表格并给出类似的动作
<form METHOD = "POST" action="processing.php">
然后将php代码放在processing.php文件中。 接收来自表单输入字段的所有值
$name = $_POST['name'];
和用户php mailto函数可以通过电子邮件地址发送邮件,您可以对收到的数据进行任何处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.