Tp6 image upload

/**
 * upload picture
 * @param $file file
 * @param $route file path configuration name
 * @param $size file size (M)
 * @param $water whether to compress
 */
function img($file, $route, $size, $water)
{

    // Check if the received file is empty
    if ($file == null) {
        return showError('No picture uploaded!');
    }
    // Determine if the file exceeds the predetermined size
    if ($_FILES['file']['size'] > (1024 * 1024 * $size)) {
        return showError('The picture is too big!');
    }
    // Determine whether the uploaded file is legal
    $temp = explode(".", $_FILES["file"]["name"]);
    $extension = end($temp); //file suffix
    if (!in_array($extension, array("jpeg", "jpg", "png"))) {
        return showError('Uploading pictures is illegal!');
    }
    // file error output
    if (isset($_FILES['userfile']['error'])) {
        return $_FILES['userfile']['error'];
    }

    // file path
    $saveName = Filesystem::disk($route)->putFile($route, $file);

    // Use exit to prevent the <div> tag file path from appearing in the returned applet
    return showSuccess(str_replace('\\', '', '/uploads/' . $saveName));
}

Guess you like

Origin blog.csdn.net/qq_43929048/article/details/125918028