<body>
<form action="upload_file.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="Submit" />
</form>
</body>
</html>
/*--"upload_file.php" 文件含有供上传文件的代码,在这个脚本中,我们增加了对文件上传的限制。用户只能上传 .gif 或 .jpeg 文件,文件大小必须小于 20 kb:*/
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&&($_FILES["file"]["size"] <20000))
{
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"]
}
}
}
else
{
echo "Invalid file"
}
?>
<?if(is_uploaded_file($_FILES['upfile']['tmp_name'])){
$upfile=$_FILES["upfile"]
$name = $upfile["name"]
$type = $upfile["type"]
$size = $upfile["size"]
$tmp_name = $upfile["tmp_name"]
//上传文件类型列表
switch ($type) {
case 'image/pjpeg' : $ok=1
break
case 'image/jpeg' : $ok=1
break
case 'image/gif' : $ok=1
break
case 'image/png' : $ok=1
break
}
if($ok){
move_uploaded_file($tmp_name,'up/'.$name)
}
}
?>
<form action="" enctype="multipart/form-data" method="post" name="upform">
上传文件:
<input type="file" name="upfile"/>
<input type="submit" value="上传"/><br>
</form>
这个 $size = $upfile["size"]就是得到文件的大小,自己判断一下,,
这是php基础,看的懂么?
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)