您必須將數據發送到您的後端代碼(php),因爲它一旦涉及到瀏覽器就不會運行。如果我是對的,你想在後臺打開文件,但你的頁面可能會重新加載,所以你不想提交表單。如果是這種情況下,你可以使用Ajax,就像這樣:
<div class = "form-group col-md-12">
<input type ="text" name = "filename" id="filename"></input>
</div>
<script>
var filename = $("#filename").val();
$.ajax({
url: myfile.php, //url to your php file with code $fopen=fopen($uploadpath.here.'.png','wb');
type: post,
data: {"fileName":filename},
success: function(result) {
// use your code to handle the result whatever you want to do here
}
})
</script>
你的PHP文件
myfile.php
<?php
$uploadPath = $_POST['fileName'];
$fopen=fopen($uploadpath.here.'.png','wb');
echo "success"; // you can return whatever you want and that will go to success function in your javascript
?>
您需要使用'ajax'來獲取值而不必提交表單。 –