PHP上传下载文件源码

2012 年 9 月 19 日1,0020

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

index.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns=".w3.org/1999/xhtml">


<head>


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<title>filelist</title>


</head>


<body>


<form action="upload_file.php" method="post"


enctype="multipart/form-data">


<label for="file">Filename:</label>


<input type="hidden" value="1000000000">


<input type="file" />


<input type="submit" value="Submit" />


</form>


<br/>


<br/>


<table>


<?php


$dir = 'upload/';


if(is_dir($dir)) {


if ($dh = opendir($dir)) {


while (($file = readdir($dh)) !== false) {


if($file!="." && $file!="") {


echo "<tr><td><a href='".$dir.$file."'>".$file."</a></td></tr>";


}


}


closedir($dh);


}


}


?>


</table>


</body>


</html>


---------------------------------------------------------------------------------------


upload_file.php


----------------------------------------------------------------------------------------


<?php


if ($_FILES["file"]["error"] > 0)


{


echo "Return Code: " . $_FILES["file"]["error"] . "<br />";


}


else


{


echo "Upload: " . $_FILES["file"]["name"] . "<br />";


echo "Type: " . $_FILES["file"]["type"] . "<br />";


echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";


echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";


if (file_exists("upload/" . $_FILES["file"]["name"]))


{


echo $_FILES["file"]["name"] . " already exists. ";


}


else


{


move_uploaded_file($_FILES["file"]["tmp_name"],


"upload/" . $_FILES["file"]["name"]);


echo "Stored in: " . "upload/" . $_FILES["file"]["name"];


}


}


header('HTTP/1.1 301 Moved Permanently');


header('Location:files.php');


?>

height=14 src="/wp-content/uploads/20120919/0645370.gif" width=14

border=0>

【责编:ivy】

0 0