Home  >  Article  >  Backend Development  >  PHP upload file class_PHP tutorial

PHP upload file class_PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:07:24753browse

[php]
header("Content-Type:text/html; charset=utf-8;");
echo "uploadclass
";
echo "
".$_FILES['file']["name"]."
";

$nabc = new uploadclass($_FILES['file']);
echo "
".$nabc->getname()."
";//Get the new name


class uploadclass {
var $location ;//Set the directory to store files
var $max_size; //The size of the uploaded file
var $event; //The initial value is success
var $filename;//Get the file name of the file saved in the folder
Function uploadclass($file) {
          $location = "./temp/";//Set the directory to store files
​​​​ $max_size = 1000000;//Size of uploaded file
           $event="success"; //The initial value is success
//Determine whether the directory exists
If(! is_dir($location))
                                                                                                    mkdir($location);
                    @chmod($location,777);
                                                                                                                                                                                 $oldFilename = $file["name"];
          $filename = explode(".",$oldFilename);
$filenameext = $filename[count($filename) - 1];
          $newFilename = "_".time()."_".rand(10000, 20000).".".$filenameext;
$this->filename = $newFilename;
                                                        echo "
".$this->$filename."
";
If(!$file['name']=="")
                                                                                       If($file['size']<$max_size)
                                                                        echo "File upload path:".$location.$file['name'];
                   move_uploaded_file($file['tmp_name'], $location.$newFilename) or $event = "Failure";
                                                                                                                                                                                      else                                                                         $event="File too large";
                                                                                                                                                   }  
       
Public function getname()
                                                                  Return $this->filename;
}  
}
?>






http://www.bkjia.com/PHPjc/477877.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/477877.html

TechArticle

[php] ?php header(Content-Type:text/html; charset=utf-8;); echo uploadclassbr/; echo br/.$_FILES[file][name].br/; $nabc = new uploadclass($_FILES[file]); echo br/.$nabc-getname().b...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn