PHP method (class) to upload files_PHP tutorial

WBOY
Release: 2016-07-21 15:44:50
Original
760 people have browsed it

Copy code The code is as follows:

/**
* Image upload method
* $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)) {
echo 'The 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/320453.htmlTechArticleCopy the code code as follows: /*** Image upload method * $maxsize=500000 = 500k; * $updir="up/"; * $upfile=$_FILES["file_img"];*/ public function Get_file_upload($upfile, $maxsize, $ ...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!