本隻程式將上傳、清單、下載做三合一,
(upload、list dir、download)
三種功能合在同一隻程式。
將以下程式碼存成 uplistdown.php 就可以上傳了。
========================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>upload</title></head>
<body>
<?
# 上傳檔案
$ttt = time(void);
if (copy($_FILES["uploads"]["tmp_name"],"(".$ttt.")".$_FILES[uploads][name])){
echo "<font color=red>".$_FILES[uploads][name]."</font> 已成功上傳,";
echo "並自動改名為:<font color=blue>(".$ttt.")".$_FILES[uploads][name]."</font
>。<font color=green>請繼續上傳下一個檔案</font>。";
}else{
echo "請上傳";
}
?>
<form action="./uplistdown.php" method="POST" enctype="multipart/form-data">
<input name="uploads" type="file"><input type="submit" value="上傳">
</form>
<?
# 下載檔案+刪除檔案
echo "<ul>";
if ($handle = opendir(".")) {
while (false !== ($mtfiles = readdir($handle))) {
if ($mtfiles != "." && $mtfiles != ".." ) {
echo "<li><a href=".$mtfiles.">$mtfiles</a></li><br>";
}
}
closedir($handle);
echo "</ul>";
}
?>
</body></html>
謝謝您提供的程式碼,執行測試是OK的,不過有個問題想請教您,就是當我上傳檔案較大的檔案時,一直無法上傳成功,不知是否有方法可解決。謝謝
[…] PHP上傳程式+清單+下載 […]
沒有下載阿請問要怎麼用
您好: 我執行出來的結果如下, 不知那裡沒設定好. 請指導
“.$_FILES[uploads][name]." 已成功上傳,"; echo “並自動改名為:(“.$ttt.")".$_FILES[uploads][name]."。請繼續上傳下一個檔案。"; }else{ echo “請上傳"; } ?>
“; if ($handle = opendir(“.")) { while (false !== ($mtfiles = readdir($handle))) { if ($mtfiles != “." && $mtfiles != “.." ) { echo "
$mtfiles
“; } } closedir($handle); echo “"; } ?>
Hi, I would liike to subscribe for this weblog to
obtain newest updates, so where can i do it please assist.
What’s Happening i am new to this, I stumbled upon this I hawve
discovered It absolutely useful and iit has aided me out loads.
I hope to give a contribution & assist different customers like itss helped
me. Great job.
Just wiish too say your article iss as amazing. The clarity in your post is simply cool and i
could assume you are an expert on this subject. Well with your permission allkw me to grab your feed to keep updated with forthcoming post.
Thanks a million and please catry on the rewarding work.