Home > Article > Backend Development > Method (class) of uploading files in Chinese courseware for second grade volume 1 using PHP
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 size of the uploaded image cannot exceed ";
}
if (move_uploaded_file($tmp_name, $updir . $newname . $extend)) {
return $newname . $extend;
}
}
The above introduces the method (class) of uploading files in PHP for the first volume of second-grade Chinese courseware, including the content of the second-grade Chinese courseware for the first volume. I hope it will be helpful to friends who are interested in PHP tutorials.