Learn to do PHP upload class with me

Source: Internet
Author: User
Tags date exit file size mkdir

up.class.php

<?php    class up{    public $f;//= $_files[xx]     public $s;//upload file size public $n;// Whether to specify a filename public $d; Specify folder   function __construct ($f, $s =1, $n =false, $d =false) {  $this->f= $f;   $this->s= $s * 1000000;   $this->n= $n;   $this->d= $d;   $this->loading (); }      Function loading () {    $this->fsize (); $this->ftype (); $this-&GT;FMV ();  } &N bsp;    Function fname () {    if ($this->n) {return $this->n. $this->ftype ();} else{return Time (). Rand (111,999). $this->ftype ();}  }      function Fdir () { if ($this-> D) { //Determines whether the user specifies the folder name if (!is_dir ($this->d)) {//Determines whether the specified folder name exists mkdir ($this->d);} return $this->d. " /";  }else{ if (!is_dir ("YMD")) {mkdir (date ("YMD"))} return date ("Ymd"). " /"; &NBSP}  }//end fdir      function fsize () {    if ($this->f[' size ']> $this->s){echo "file exceeds size"; exit ();} Else{ return true;  }      function ftype () { switch ($this->f[' type ']) {case "image/x -png ": $ok =". png; Break Case "Image/png": $ok = ". png"; Break Case "Application/pdf": $ok = ". pdf"; Break Case "Image/pjpeg": $ok = ". jpg"; Break Case "Image/jpeg": $ok = ". jpg"; Break Case "Image/jpg": $ok = ". jpg"; Break Default: $ok =false; Break } if ($ok) {  return $ok;} else{ echo "Incorrect file type";  exit ();}  }       function FMV () {    &NBSP;MOVE_UP Loaded_file ($this->f[' tmp_name '), $this->fdir (). $this->fname ());   &NBSP}     }    ?>   test.php upload file   <?php include ("up.class.php");  if (!empty ($_post[' Sub ')) {  foreach ($_files as $id => $v) {  New up ($_files[$id]);  }  } &nb SP;? > <form action= "" method= "Post" enctype= "Multipart/form-data" > <input type= "file" Name= "P1" ><br> <input type= "FIle "Name=" P2 "><br> <input type=" file "name=" P3 "><br> <input type=" file "Name=" P4 "><br > <input type= "File" Name= "P5" ><br> <input type= "file" Name= "P6" ><br> <input type= " Submit "Name=" sub "value=" Upload "> </form>    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.