The code is as follows |
Copy Code |
<form name= "Form1" enctype= "Multipart/form-data" method= "POST" action= "" > <label for= "Filefield" ></label> <input type= "File" Name= "Filefield" id= "Filefield" > <input type= "Submit" name= "button" id= "button" value= "Upload file" > </form> <?php /* * $NAME; Upload file name * $size: Upload file size * $PATH; File Original path * $newpath: Set a new path * $not: An array of file types that are prohibited from uploading * $notsize: Limit the value of the file size * $move: Upload file source * */ Class FileUpload { Public $name; Public $size; public $path; Public $newpath; Public $not = Array (); Public $notsize; Public $move; Public $allfile = Array (); function __construct ($name, $size, $path, $newpath, $not, $notsize) { $this->name = $name; $this->size = $size/1048576; $this->path = $path; $this->newpath = $newpath; $this->not = Explode (', ', $not); $this->notsize = $notsize; $this->upload (); } /* * Upload Program * First determine whether the directory exists * Determine file type and size */ function upload () { if (!file_exists ($this->newpath)) { echo "<script>alert (' This directory does not exist! ') </script>; Return }else{ $arr = Explode ('. ', $this->name); if (In_array ($arr [1], $this->not)) { echo "<script>alert (' This type of file is forbidden to upload! ') </script> "; Return }else if ($this->name = = ") { echo "<script>alert (' Please select uploaded file! ') </script> "; Return }else if ($this->size> $this->notsize) { echo "<script>alert (' upload file exceeds specified size! ') </script> "; Return }else if (file_exists ("$this->newpath".) $this->name ")) { echo "<script>alert (' This file already exists! ') </script> "; Return } else{ $this->move = Move_uploaded_file ($this->path, $this->newpath. $this->name); $this->move (); } } } /* * To determine whether the file upload success */ function Move () { if ($this->move) { echo "<script>alert (' File Upload success! ') </script>; Return }else{ echo "<script>alert (' upload failed! ') </script>; Return } } } |
$fu = new FileUpload ($array [name], $array [size], $array [Tmp_name], './www.111cn.net/', ' Exe,rar ', 5);