![](/img/trans.png)
[英]How can I send a text file to all open browsers on a website when a user submits a PHP form
[英]how can i open a text file from php using fileselector
我想使用html中的文件選擇器在php中打開文本文件
這是我的HTML代碼
<form>
<select>
<option value="">Select a source</option>
<option value="NOTEPAD">NOTEPAD</option>
<option value="XML">XML</option>
<br>
<input type="file" name="datafile" id="fileid" size="40">
<br>
<input type="button" value="Read Source" onclick="showRSS('test')"></input>
</select>
</form>
我試圖從ID="fileid"
獲取路徑並將其發送到php
var num;
num="xyz";
var loc;
var loc = document.getElementById("fileid").value;
xmlhttp.open("GET","read.phpq="+encodeURIComponent(num)+"&x="+encodeURIComponent(loc),true);
xmlhttp.send();
我的PHP代碼是:
$lc=$_GET['x'];
$i=$_GET['q'];
$myfile = fopen($lc, "r") or die("Unable to open file!");
但是我的文件路徑顯示為C:\\ fakepath \\ try.txt,我如何發送正確的路徑到我的PHP腳本。
在要保存的服務器上嘗試temp_name。
您必須首先將文件上傳到服務器。 如果您在選擇文件時想要這個東西,請使用jquery文件上載器而不是fileselector控件。 因為Jquery文件上傳器將直接在給定路徑上將文件上傳到服務器上。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.