- <?php
- class upload {
- public $files;//源文件
- public $path;//路径
- function __construct($files,$path) {
- $this->files=$files;
- $this->path=$path;
- }
- function istype(){
- $url = "upfile/";
- $upfile =$_FILES["upfile"];
- $name = date(YmdHis)."_".$upfile["name"];
- $type = $upfile["type"];
- $size = $upfile["size"];
- $tmp = $upfile["tmp_name"];
- $error = $upfile["error"];
- if($error != 0){
- echo "上传失败!";
- }
- if($size > 5000000){
- echo "文件太大!";
- }
- switch($type){
- case "image/pjpeg": $ok=".jpg";
- break;
- case "image/jpeg": $ok=".jpg";
- break;
- case "image/gif": $ok=".gif";
- break;
- case "image/png": $ok=".png";
- break;
- }
- if($error == 0 && $ok){
- move_uploaded_file($tmp,$url.$name);
- echo "上传成功!";
- }
- }
- }
- if($_POST[submit]){
- $up = new upload($_FILES[upfile],"upfile/");
- $up -> istype();
- }
- ?>
- <form enctype="multipart/form-data" method="post" action="" name="upform">
- 上传文件:
- <input type="file" name="upfile"/>小于5M<br/>
- <input type="submit" name="submit" value="上传"/>
- </form>
复制代码
|