什麼,我想實現的是,我想創建一個鏈接,通過PHP
網頁上的新上載文件的某處下載文件的PHP代碼如下所示:
`是否可以創建<a href...</a>上傳的文件與PHP?
$target_path = "uploads/";
$filename = $_FILES['userfile']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$allowed = array('gp5','gp4' ,'gp3');
$filename = $_FILES['userfile']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed)) {
echo 'not a valid file extension';
}
else {
$target_path = $target_path . basename($_FILES['userfile']['name']);
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) {
echo "The file ". basename($_FILES['userfile']['name'])." has been uploaded";
} else {
echo "There was an error uploading the file, please try again!";
}
}
`
是的,當然是。只需將文件複製到可公開訪問的路徑(或確保'$ target_path'可到達)並鏈接到它。或者,添加一個可公開訪問的PHP文件,該文件執行一些身份驗證,然後從不可公開訪問的位置流式傳輸文件。 – meagar
有關類似問題,請參閱https://www.google.com/search?q=site:stackoverflow.com+php%20download%20links%20for%20uploaded%20files。看來你還需要一個教程。 – mario
@mario,google.com和stackoverflow都沒有這個問題的答案 –