2015-10-16 105 views
0

我想創建一個PHP網站來管理我的文件在服務器上。所以我在我的服務器上安裝XAMPP並在其中運行我的程序。讓說,我在C:上安裝它:驅動PHP訪問服務器驅動器

我可以上傳文件到另一個驅動器,例如d:或E:使用此代碼:

move_uploaded_file($_FILES['file']['tmp_name'], $drive.':/'.$cat.'/'.$catname.'/'.$newfilename) 

我的目標驅動器$驅動器,$貓爲我的類別組,類別名稱爲adn $ catname。我可以輕鬆上傳文件。

問題是,當我想用​​這些代碼來呼籲我的PHP文件:

<audio controls> 
    <source src="'.$query['a_drive'].':/'.$query['c_group'].'/'.$query['c_name'].'/'.$query['a_link'], 'r'.'" type="audio/'.$extension.'"> 
    Your browser does not support the audio element. 
</audio> 

$query是我的查詢從數據庫中獲取數據(SELECT * bla bla

我的瀏覽器無法打開我希望要打開的文件,它返回我不能訪問文件:

不允許加載本地資源:

有誰知道如何解決這個問題?

+0

本地服務器管理的一個奇怪的方法 – 2015-10-16 04:59:00

+0

我想分享這個文件服務器到另一臺PC,所以另一臺PC只是連接到這個應用程序,讓說:10.10.1.1然後打開應用程序,然後他們可以搜索/打開任何文件在這裏。我需要一個應用程序,因爲我想輕鬆搜索文件... –

+0

他們在同一個網絡上?只需創建一個分享 – 2015-10-16 05:05:44

回答

1

問題是您打印服務器上文件的本地路徑。但是,當瀏覽器打開頁面時,它將解釋客戶端本地的路徑並阻止對其的訪問。另外文件在服務器上,而不在客戶端上。

您可以通過Web服務器(虛擬文件夾)訪問保存文件的文件夾,並在html代碼中打印url(而不是本地文件路徑)來配置Web服務器。

或者,您可以使用php腳本基於服務器上的get參數打開文件,並使用適當的mime標題打印其內容。 html文件中的鏈接將指向這個php文件,並指向相應的參數。

UPDATE: file.php - 這個輸出文件到客戶端

<?php 
     $filename=$_GET['filename']; //parameter identifying the file to be downloaded. Should not be direct path as in this simple example, rather than the id of the file's data stored in a database. You need to add that piece of code. 
     header('Content-Type: text/plain'); //set MIME type - you need to store this along your path to the file, you can get it from $_FILES['uploadedfilename']['type'] when a file is uploaded via php 
     header("Content-disposition: inline"); //advises the browser to open the file inside the browser 
     readfile($filename); //outputs the file 
?> 

HTML鏈接:

<audio controls> 
    <source src="file.php?filename=yourfilename" type="..."> 
</audio> 

讓我再次強調:用一個id來引用文件,不一條路徑。

+0

你的意思是我需要使用fopen()嗎?或者我需要使用什麼功能? –

+0

更新了我的回答 – Shadow

+0

完美。這是我正在尋找的。非常感謝。所以沒有辦法直接從HTML中直接播放它? –