Home  >  Article  >  Backend Development  >  PHP upload method (class)_PHP tutorial

PHP upload method (class)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:38:26752browse

A very simple, commonly used PHP method. I took it out from the class for everyone. You can use it directly, or you can continue to improve it. The bkJia video tutorial also explains the PHP upload method in detail. Please refer to it. Just a moment

/**
* Image upload method-source and bkJia Chinese website
* $maxsize=500000 = 500k;
* $updir="up/";
* $upfile=$_FILES["file_img"];
​*/
public function Get_file_upload($upfile, $maxsize, $updir, $newname = date) {

if ($newname == date)
$newname = date("Ymdhs"); //Use date as file name
$name = $upfile["name"];
$type = $upfile["type"];
$size = $upfile["size"];
$tmp_name = $upfile["tmp_name"];

switch ($type) {
case image/pjpeg :
case image/jpeg :
$extend = ".jpg";
Break;
case image/gif :
$extend = ".gif";
Break;
case image/png :
$extend = ".png";
Break;
}
if (empty ($extend)) {
The echo file type is incorrect, only JPG GIF PNG format can be used;
}
if ($size > $maxsize) {
$maxpr = $maxsize / 1000;
echo "Warning! The uploaded image size cannot exceed";
}
if (move_uploaded_file($tmp_name, $updir . $newname . $extend)) {
Return $newname . $extend;
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486498.htmlTechArticleA very simple, commonly used PHP method, I took it out from the class for you, you can do it directly Use it, or you can continue to improve it. PHP uploading is also explained in detail in the PHP100 video tutorial...
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