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;
}
}