下面的代码演示了php中如何获取用户上传的文件,并限制文件类型的一般图片文件,最后保存到服务器
HTML源码:
<html>
<head>
< >Upload Form</ >
</head>
<body>
<form action=\"UploadSingle.php\" method=\"post\" enctype=\"multipart/form-data\">
Upload a file: <input type=\"file\" name=\"thefile\"><br><br>
<input type=\"submit\" name=\"Submit\" value=\"Submit\">
</form>
</body>
</html>
php上传并判断文件类型源码
<?php
$aErrors = \"\";
if ( !empty( $thefile_name ) ) // no file selected
{
$$thefile_type=$_FILES[\"file\"][\"type\"];
if ( ( $thefile_type == \"image/gif\" ) ||
( $thefile_type == \"image/pjpeg\" ) ||
( $thefile_type == \"image/jpeg\" ) ){
if ( $thefile_size < ( 1024 * 100 ) ){
$aCur Path = dirname( $PATH_TRANSLATED );
$aNewName = $aCur Path . $thefile_name;
copy( $thefile, $aNewName );
} else {
$aErrors .= \"超过最大上传文件限制\";
}
} else {
$aErrors .= \"文件不是图片\";
}
} else{
$aErrors .= \"没有选中任何文件上传\";
}
?> 继续阅读与本文标签相同的文章
上一篇 :
出炉!一线城市程序员工资大调查
下一篇 :
10分钟带你打开深度学习大门,代码已开源
-
超进化,时尚玩主的全新一代名爵ZS,起步只要7.98万
2026-05-14栏目: 教程
-
微信 7.0.8 内测新功能,教你如何激活它
2026-05-14栏目: 教程
-
美女机器人刚上市就售罄,除了生孩子,其他什么都能干!
2026-05-14栏目: 教程
-
互联网之光大会的黑科技,总有一款惊艳你!
2026-05-14栏目: 教程
-
微信宣布一项新举措,关系到每一个用户,网友一致力挺:干得漂亮!
2026-05-14栏目: 教程
