iT邦幫忙

0

有關Apache架設網站問題

  • 分享至 

  • xImage

小弟是Apache新手,還請版上大大多多包涵

小弟今天想使用Apache架設一個網站能讓外部直接使用如以下url的格式(模擬加入判斷條件的格式)去下載ras.bin檔案
http://ip:port/FirmwareDownload?deviceSoftwareId=1305&deviceSoftwareName=ras.bin

但目前小弟也只會使用如下url來去下載ras.bin檔案
http://ip:port/download.php?path=ras.bin

如果要把
http://ip:port/FirmwareDownload?deviceSoftwareId=1305&deviceSoftwareName=ras.bin
導到
http://ip:port/test/ras.bin

類似做法是有辦法做到的嗎?
謝謝

以下是我目前的寫法去修改.php檔和.html檔
目前使用url http://ip:port/download.php?path=ras.bin
可成功下載ras.bin檔案,但如果要符合
http://ip:port/FirmwareDownload?deviceSoftwareId=1305&deviceSoftwareName=ras.bin
格式的話要怎麼修改呢?中間需要加入&以及;的url格式
download.html:

<html>
<head>
<title>Download Files</title>
</head>
<body>
<p><a href="download.php?path=test/ras.bin">Download BIN file</a></p>
</body>
</html>

download.php:

<?php
if(isset($_GET['path']))
{
//Read the url
$url = $_GET['path'];

//Clear the cache
clearstatcache();

//Check the file path exists or not
if(file_exists($url)) {

//Define header information
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($url).'"');
header('Content-Length: ' . filesize($url));
header('Pragma: public');

//Clear system output buffer
flush();

//Read the size of the file
readfile($url,true);

//Terminate from the script
die();
}
else{
echo "File path does not exist.";
}
}
echo "File path is not defined."

?>
看更多先前的討論...收起先前的討論...
copemoe iT邦研究生 1 級 ‧ 2022-11-23 17:39:08 檢舉
可以辦到
chan15 iT邦新手 2 級 ‧ 2022-11-24 08:48:28 檢舉
可以辦到啊,用 .htaccess 寫 rewerite rules,看你前段的網址正規要多嚴謹
看你的網址有參數就知道根本不能用改 .htaccess 來達成,而是你必須寫好PHP的語法之後,當這個頁面處理參數就能找到檔案然後出現下載提示,這才是正規作法,不然就講1305 跟 1405 或 6655 的差異在哪
而且這各網址一看就知道是韌體更新
難道不需要比對目前的版本 ? 目前版本是 1305,網站上最新的也是 1305,請問是要更新還是不要更新 ?
s2266888 iT邦新手 5 級 ‧ 2022-11-24 16:25:52 檢舉
小弟現在只會簡單的 http://ip:port/download.php?path=ras.bin,但如果要加上更多條件(隨意條件皆可)加上&和;的話.php和.html要如何做修改呢?

抱歉小弟我對php語法還不是很熟悉
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1

一定可以辦到

關鍵字「RW規則」「HTACCESS」「httpd.conf」

我要發表回答

立即登入回答