您的位置:首页 > 编程语言 > PHP开发

PHP上传文件简单实例

2013-09-03 22:56 666 查看
首先建立一个简单的html 页面如下所示:

lelexie.html

<html>
<body>

<form action="fileUpload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Upload" />
</form>

</body>
</html>
接下来建立upload.php

<?php
// Check for any errors.
if ($_FILES["file"]["error"] > 0)
{
print("Error: ". $_FILES["file"]["error"]);
}

else
{
// Display statistics.
print("Uploaded: " . $_FILES["file"]["name"]. "<br />");
print("Type: " . $_FILES["file"]["type"] . "<br />");
print("Size: " . $_FILES["file"]["type"] . "<br />");

// Save file to permanent location.
move_uploaded_file($_FILES["file"]["tmp_name"],
"uploads/" . $_FILES["file"]["name"]);
}
?>


接下来检查文件的类型和大小
if (_$FILES["file"]["type"] == "image/gif")
print("The file is a gif image.");
if (_$FILES["file"]["size"] < 1000000)
print("File size: " . $_FILES["file"]["size"] . ". <br />");

else
print("The file is too big. <br />");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: