Example #1
0
function thumb($filename, $destination = null, $dst_w = null, $dst_h = null, $isReservedSource = false, $scale = 0.5)
{
    list($src_w, $src_h, $imagetype) = getimagesize($filename);
    if (is_null($dst_w) || is_null($dst_h)) {
        $dst_w = ceil($src_w * $scale);
        $dst_h = ceil($src_h * $scale);
    }
    $mime = image_type_to_mime_type($imagetype);
    $createFun = str_replace("/", "createfrom", $mime);
    $outFun = str_replace("/", null, $mime);
    $src_image = $createFun($filename);
    $dst_image = imagecreatetruecolor($dst_w, $dst_h);
    imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
    //image_50/sdfsdkfjkelwkerjle.jpg
    if ($destination && !file_exists(dirname($destination))) {
        mkdir(dirname($destination), 0777, true);
    }
    $dstFilename = $destination == null ? getUniName() . "." . getExt($filename) : $destination;
    $outFun($dst_image, $dstFilename);
    imagedestroy($src_image);
    imagedestroy($dst_image);
    if (!$isReservedSource) {
        unlink($filename);
    }
    return $dstFilename;
}
/**
 * 生成缩略图
 * @param string $filename
 * @param string $destination
 * @param int $dst_w
 * @param int $dst_h
 * @param bool $isReservedSource
 * @param number $scale
 * @return string
 */
function thumb($filename, $destination = null, $dst_w, $dst_h = NULL, $isReservedSource = true)
{
    list($src_w, $src_h, $imagetype) = getimagesize($filename);
    if ($src_w <= $dst_w) {
        $dst_w = $src_w;
        $dst_h = $src_h;
    }
    if (is_null($dst_h)) {
        $dst_h = scaling($src_w, $src_h, $dst_w);
    }
    $mime = image_type_to_mime_type($imagetype);
    $createFun = str_replace("/", "createfrom", $mime);
    $outFun = str_replace("/", null, $mime);
    $src_image = $createFun($filename);
    $dst_image = imagecreatetruecolor($dst_w, $dst_h);
    imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
    if ($destination && !file_exists(dirname($destination))) {
        mkdir(dirname($destination), 0777, true);
    }
    $dstFilename = $destination == null ? getUniName() . "." . getExt($filename) : $destination;
    $outFun($dst_image, $dstFilename);
    imagedestroy($src_image);
    imagedestroy($dst_image);
    if (!$isReservedSource) {
        unlink($filename);
    }
    return $dstFilename;
}
Example #3
0
function thumb($filename, $destination = null, $dst_w = null, $dst_h = null, $isReservedSource = true, $scale = 0.5)
{
    //getimagesize() —— 取得图片的长宽。
    list($src_w, $src_h, $imagetype) = getimagesize($filename);
    if (is_null($dst_w) || is_null($dst_h)) {
        $dst_w = ceil($src_w * $scale);
        $dst_h = ceil($src_h * $scale);
    }
    $mime = image_type_to_mime_type($imagetype);
    $createFun = str_replace("/", null, $mime);
    $outFun = str_replace("/", null, $mime);
    $src_image = $createFun($filename);
    $dst_image = imagecreatetruecolor($dst_w, $dst_h);
    //imagecopyresampled — 重采样拷贝部分图像并调整大小
    imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
    if ($destination && !file_exists(dirname($destination))) {
        mkdir(dirname($destination), 0777, TRUE);
    }
    $dstFilename = $destination = null ? getUniName() . "." . getExt($filename) : $destination;
    $outFun($dst_image, $dstFilename);
    imagedestroy($src_image);
    imagedestroy($dst_image);
    if (!$isReservedSource) {
        unlink($filename);
    }
    return $dstFilename;
}
Example #4
0
/**
 * 生成缩略图
 * @param string $fileName
 * @param string $destination
 * @param int $dst_w
 * @param int $dst_h
 * @param number $scale
 * @param bool $isReservedSource
 * @return Ambigous <string, unknown>
 */
function thumb($fileName, $destination = null, $dst_w = null, $dst_h = null, $scale = 0.5, $isReservedSource = true)
{
    //得到文件类型
    list($src_w, $src_h, $imagetype) = getimagesize($fileName);
    if (is_null($dst_w) || is_null($dst_h)) {
        $dst_w = ceil($src_w * $scale);
        $dst_h = ceil($src_h * $scale);
    }
    $mime = image_type_to_mime_type($imagetype);
    //得到方法名,通过拼接字符串得到,这样子做是为了能够处理不同类型的图片
    $createFun = str_replace("/", "createfrom", $mime);
    $outFun = str_replace("/", null, $mime);
    $src_image = $createFun($fileName);
    $dst_image = imagecreatetruecolor($dst_w, $dst_h);
    imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
    $destination = $destination == null ? getUniName() . '.' . getExt($fileName) : $destination;
    $outFun($dst_image, $destination);
    imagedestroy($dst_image);
    imagedestroy($src_image);
    if (!$isReservedSource) {
        unlink($fileName);
    }
    return $destination;
}
Example #5
0
    }
    if ($size > $maxSize) {
        exit("文件过大");
    }
    if ($imgFlag) {
        //如何验证图片是否是一个真正的图片类型
        //getimagesize($filename):验证文件是否是图片类型
        $info = getimagesize($tmp_name);
        //var_dump($info);exit;
        if (!$info) {
            exit("不是真正的图片类型");
        }
    }
    //需要判断下文件是否是通过HTTP POST方式上传上来的
    //is_uploaded_file($tmp_name):
    $filename = getUniName() . "." . $ext;
    $path = "uploads";
    if (!file_exists($path)) {
        mkdir($path, 0777, true);
    }
    $destination = $path . "/" . $filename;
    if (is_uploaded_file($tmp_name)) {
        if (move_uploaded_file($tmp_name, $destination)) {
            $mes = "文件上传成功";
        } else {
            $mes = "文件移动失败";
        }
    } else {
        $mes = "文件不是通过HTTP POST方式上传上来的";
    }
} else {
Example #6
0
function uploadFile($path = "uploads", $allowExt = array("gif", "jpeg", "png", "jpg", "wbmp"), $maxSize = 2097152, $imgFlag = true)
{
    if (!file_exists($path)) {
        mkdir($path, 0777, true);
    }
    $files = buildInfo();
    $i = 0;
    if (!($files && is_array($files))) {
        return;
    }
    foreach ($files as $file) {
        if ($file['error'] == UPLOAD_ERR_OK) {
            $ext = getExt($file['name']);
            // 检查文件扩展名
            if (!in_array($ext, $allowExt)) {
                exit("非法文件类型");
            }
            // 检查是否真正图片类型
            if ($imgFlag) {
                if (!getimagesize($file['tmp_name'])) {
                    exit("不是真正图片类型");
                }
            }
            // 上传文件的大小
            if ($file['size'] > $maxSize) {
                exit("上传文件过大");
            }
            // 是否通过HTTP POST上传
            if (!is_uploaded_file($file['tmp_name'])) {
                exit("不是通过HTTP POST方式上传");
            }
            $filename = getUniName() . "." . $ext;
            $destination = $path . "/" . $filename;
            if (move_uploaded_file($file['tmp_name'], $destination)) {
                $file['name'] = $filename;
                unset($file['error'], $file['tmp_name'], $file['size'], $file['type']);
                //注销没用信息
                $uploadedFiles[$i] = $file;
                $i++;
            }
        } else {
            switch ($file['error']) {
                case 1:
                    $mes = "超过了配置文件上传文件的大小";
                    // UPLOAD_ERR_INI_SIZE
                    break;
                case 2:
                    $mes = "超过了表单设置上传文件的大小";
                    // UPLOAD_ERR_FORM_SIZE
                    break;
                case 3:
                    $mes = "文件部分被上传";
                    // UPLOAD_ERR_PARTIAL
                    break;
                case 4:
                    $mes = "没有文件被上传";
                    // UPLOAD_ERR_NO_FILE
                    break;
                case 6:
                    $mes = "没有找到临时目录";
                    // UPLOAD_ERR_NO_TMP_DIR
                    break;
                case 7:
                    $mes = "文件不可写";
                    // UPLOAD_ERR_CANT_WRITE
                    break;
                case 8:
                    $mes = "由于PHP的扩展程序终端了文件上传";
                    // UPLOAD_ERR_EXTENSION
            }
            echo $mes;
        }
    }
    return $uploadedFiles;
}
Example #7
0
/**
 * 针对于单文件、多个单文件、多文件的上传
 * @param array $fileInfo
 * @param string $path
 * @param string $flag
 * @param number $maxSize
 * @param array $allowExt
 * @return string
 */
function uploadFile($fileInfo, $path = './uploads', $flag = true, $maxSize = 1048576, $allowExt = array('jpeg', 'jpg', 'png', 'gif'))
{
    //$flag=true;
    //$allowExt=array('jpeg','jpg','gif','png');
    //$maxSize=1048576;//1M
    //判断错误号
    if ($fileInfo['error'] === UPLOAD_ERR_OK) {
        //检测上传得到小
        if ($fileInfo['size'] > $maxSize) {
            $res['mes'] = $fileInfo['name'] . '上传文件过大';
        }
        $ext = getExt($fileInfo['name']);
        //检测上传文件的文件类型
        if (!in_array($ext, $allowExt)) {
            $res['mes'] = $fileInfo['name'] . '非法文件类型';
        }
        //检测是否是真实的图片类型
        if ($flag) {
            if (!getimagesize($fileInfo['tmp_name'])) {
                $res['mes'] = $fileInfo['name'] . '不是真实图片类型';
            }
        }
        //检测文件是否是通过HTTP POST上传上来的
        if (!is_uploaded_file($fileInfo['tmp_name'])) {
            $res['mes'] = $fileInfo['name'] . '文件不是通过HTTP POST方式上传上来的';
        }
        if ($res) {
            return $res;
        }
        //$path='./uploads';
        if (!file_exists($path)) {
            mkdir($path, 0777, true);
            chmod($path, 0777);
        }
        $uniName = getUniName();
        $destination = $path . '/' . $uniName . '.' . $ext;
        if (!move_uploaded_file($fileInfo['tmp_name'], $destination)) {
            $res['mes'] = $fileInfo['name'] . '文件移动失败';
        }
        $res['mes'] = $fileInfo['name'] . '上传成功';
        $res['dest'] = $destination;
        return $res;
    } else {
        //匹配错误信息
        switch ($fileInfo['error']) {
            case 1:
                $res['mes'] = '上传文件超过了PHP配置文件中upload_max_filesize选项的值';
                break;
            case 2:
                $res['mes'] = '超过了表单MAX_FILE_SIZE限制的大小';
                break;
            case 3:
                $res['mes'] = '文件部分被上传';
                break;
            case 4:
                $res['mes'] = '没有选择上传文件';
                break;
            case 6:
                $res['mes'] = '没有找到临时目录';
                break;
            case 7:
            case 8:
                $res['mes'] = '系统错误';
                break;
        }
        return $res;
    }
}
Example #8
0
/**
 * 多文件上传
 *
 */
function uploadFiles($allowExt = array("gif", "jpeg", "jpg", "png", "wbmp"), $maxSize = 2097152, $imgFlag = true, $path = "uploads")
{
    // 检查文件夹
    if (!file_exists($path)) {
        mkdir($path, 0777, true);
    }
    $i = 0;
    $files = @buildInfo();
    if (!isset($files)) {
        exit("请不要上传不能被识别的文件,错误:\$" . "_" . "FILES" . " is empty");
    }
    foreach ($files as $file) {
        $tmp_name = $file['tmp_name'];
        $error = $file['error'];
        $size = $file['size'];
        $type = $file['type'];
        $name = $file['name'];
        if ($error == UPLOAD_ERR_OK) {
            $ext = getExt($name);
            // 检查文件拓展名
            if (!in_array($ext, $allowExt)) {
                exit("非法文件类型");
            }
            // 检查大小
            if ($size > $maxSize) {
                exit("文件过大");
            }
            // 检查是否是使用POST HTTP方式上传
            if (!is_uploaded_file($tmp_name)) {
                exit("不是使用POST HTTP方式上传");
            }
            // 检查是否是图片类型
            if ($imgFlag && !getimagesize($tmp_name)) {
                exit("不是真正的图片类型");
            }
            $uniName = getUniName() . '.' . $ext;
            $destination = $path . "/" . $uniName;
            if (move_uploaded_file($tmp_name, $destination)) {
                $file['name'] = $uniName;
                unset($file['tmp_name'], $file['error'], $file['size'], $file['type']);
                $uploadedFiles[$i] = $file;
                $i++;
            }
        } else {
            switch ($error) {
                case 1:
                    $mes = "超过了配置文件上传文件的大小";
                    //UPLOAD_ERR_INI_SIZE
                    break;
                case 2:
                    $mes = "超过了表单设置上传文件的大小";
                    //UPLOAD_ERR_FORM_SIZE
                    break;
                case 3:
                    $mes = "文件部分被上传";
                    //UPLOAD_ERR_PARTIAL
                    break;
                case 4:
                    $mes = "没有文件被上传";
                    //UPLOAD_ERR_NO_FILE
                    break;
                case 6:
                    $mes = "没有找到临时目录";
                    //UPLOAD_ERR_NO_TMP_DIR
                    break;
                case 7:
                    $mes = "文件不可写";
                    //UPLOAD_ERR_CANT_WRITE;
                    break;
                case 8:
                    $mes = "由于PHP的扩展程序中断了文件上传";
                    //UPLOAD_ERR_EXTENSION
                    break;
            }
            echo $mes;
        }
    }
    return $uploadedFiles;
}
Example #9
0
function uploadFile($path, $allowExt = array("gif", "jpeg", "png", "jpg", "wbmp"), $maxSize = 2097152, $imgFlag = true)
{
    $mes = "";
    if (!file_exists($path)) {
        mkdir($path, 0755, true);
    }
    $i = 0;
    $files = buildInfo();
    if (!($files && is_array($files))) {
        return;
    }
    foreach ($files as $file) {
        if ($file['error'] === UPLOAD_ERR_OK) {
            $ext = getExt($file['name']);
            //检测文件的扩展名
            if (!in_array($ext, $allowExt)) {
                exit("Not a file!");
            }
            //校验是否是一个真正的图片类型
            if ($imgFlag) {
                if (!getimagesize($file['tmp_name'])) {
                    exit("Not a real image type!");
                }
            }
            //上传文件的大小
            if ($file['size'] > $maxSize) {
                exit("Err_MaxSize!");
            }
            if (!is_uploaded_file($file['tmp_name'])) {
                exit("Not post by HTTP!");
            }
            $filename = getUniName() . "." . $ext;
            $destination = $path . "/" . $filename;
            if (move_uploaded_file($file['tmp_name'], $destination)) {
                $file['name'] = $filename;
                //discharge temporary file
                unset($file['tmp_name'], $file['size'], $file['type']);
                $uploadedFiles[$i] = $file;
                $i++;
            }
        } else {
            switch ($file['error']) {
                case 1:
                    $mes = "Error: upload_ERR_INI_SIZE";
                    //UPLOAD_ERR_INI_SIZE
                    break;
                case 2:
                    $mes = "UPLOAD_ERR_FORM_SIZE";
                    //UPLOAD_ERR_FORM_SIZE
                    break;
                case 3:
                    $mes = "UPLOAD_ERR_PARTIAL";
                    //UPLOAD_ERR_PARTIAL
                    break;
                    /*	case 4:
                    					$mes="UPLOAD_ERR_NO_FILE";//UPLOAD_ERR_NO_FILE
                    					break;
                    			*/
                /*	case 4:
                					$mes="UPLOAD_ERR_NO_FILE";//UPLOAD_ERR_NO_FILE
                					break;
                			*/
                case 6:
                    $mes = "UPLOAD_ERR_NO_TMP_DIR";
                    //UPLOAD_ERR_NO_TMP_DIR
                    break;
                case 7:
                    $mes = "UPLOAD_ERR_CANT_WRITE";
                    //UPLOAD_ERR_CANT_WRITE;
                    break;
                case 8:
                    $mes = "UPLOAD_ERR_EXTENSION";
                    //UPLOAD_ERR_EXTENSION
                    break;
            }
            echo $mes;
        }
    }
    return $uploadedFiles;
}
function uploadFile($path = "uploads", $allowExt = array("gif", "jpeg", "jpg", "png", "wbmp"), $maxSize = 10485760, $imgFlag = true)
{
    //判断并构建目录
    if (!file_exists($path)) {
        mkdir($path, 0777, true);
    }
    $i = 0;
    //获取文件信息
    $files = buildInfo();
    //循环文件信息
    foreach ($files as $file) {
        //判断是否上传成功
        if ($file['error'] == UPLOAD_ERR_OK) {
            $ext = getExt($file['name']);
            //检查文件的扩展名
            if (!in_array($ext, $allowExt)) {
                exit("非法文件类型");
            }
            //校验是否是真正的图片类型
            if ($imaFlag) {
                if (getimagesize($file['tmp_name'])) {
                    exit("不是真正的图片类型");
                }
            }
            //上传文件的大小
            if ($file['size'] > $maxSize) {
                exit("上传文件过大");
            }
            //判断是否通过HTTP POST方式上传上来的
            if (!is_uploaded_file($file['tmp_name'])) {
                exit("不是通过HTTP POST方式上传上来的");
            }
            //生成文件唯一的字符串并命名给该文件
            $filename = getUniName() . "." . $ext;
            //文件详细存储路径
            $destination = $path . "/" . $filename;
            //移动生成的随机文件名并存储到相应目录下去
            if (move_uploaded_file($file['tmp_name'], $destination)) {
                //命名文件名
                $file['name'] = $filename;
                //unset()函数丢弃数组内相应的数据
                unset($file['error'], $file['tmp_name'], $file['size'], $file['type']);
                //生成数组名赋值
                $uploadedFiles[$i] = $file;
                $i++;
            }
        } else {
            switch ($file['error']) {
                case 1:
                    $mes = "超过了配置文件上传文件的大小";
                    //upload_max_filesize = 64M
                    break;
                case 2:
                    $mes = "超过了表单设置上传文件的大小";
                    //post_max_size = 10M
                    break;
                case 3:
                    $mes = "文件部分被上传";
                    break;
                case 4:
                    $mes = "没有文件被上传";
                    break;
                case 6:
                    $mes = "没有找到临时目录";
                    break;
                case 7:
                    $mes = "文件不可写";
                    break;
                case 8:
                    $mes = "由于PHP的扩展程序中断了文件上传";
                    break;
            }
            echo $mes;
        }
    }
    return $uploadedFiles;
}
Example #11
0
function uploadFile($fileInfo, $path = "uploads", $allowExt = array("gif", "jpeg", "jpg", "png", "wbmp"), $maxSize = 1512000, $imgFlag = true)
{
    //$allowExt=array("gif","jpeg","jpg","png","wbmp");
    //		$maxSize=1512000;
    //		$imgFlag=true;
    //判断下错误信息
    if ($fileInfo['error'] == UPLOAD_ERR_OK) {
        $ext = getExt($fileInfo['name']);
        //限制上传文件类型
        if (!in_array($ext, $allowExt)) {
            exit("非法文件类型");
        }
        if ($fileInfo['size'] > $maxSize) {
            exit("文件过大");
        }
        if ($imgFlag) {
            //如何验证图片是否是一个真正的图片类型
            //getimagesize($filename):验证文件是否是图片类型
            $info = getimagesize($fileInfo['tmp_name']);
            //var_dump($info);exit;
            if (!$info) {
                exit("不是真正的图片类型");
            }
        }
        //需要判断下文件是否是通过HTTP POST方式上传上来的
        //is_uploaded_file($tmp_name):
        $filename = getUniName() . "." . $ext;
        if (!file_exists($path)) {
            mkdir($path, 0777, true);
        }
        $destination = $path . "/" . $filename;
        if (is_uploaded_file($fileInfo['tmp_name'])) {
            if (move_uploaded_file($fileInfo['tmp_name'], $destination)) {
                $mes = "文件上传成功";
            } else {
                $mes = "文件移动失败";
            }
        } else {
            $mes = "文件不是通过HTTP POST方式上传上来的";
        }
    } else {
        switch ($fileInfo['error']) {
            case 1:
                $mes = "超过了配置文件上传文件的大小";
                //UPLOAD_ERR_INI_SIZE
                break;
            case 2:
                $mes = "超过了表单设置上传文件的大小";
                //UPLOAD_ERR_FORM_SIZE
                break;
            case 3:
                $mes = "文件部分被上传";
                //UPLOAD_ERR_PARTIAL
                break;
            case 4:
                $mes = "没有文件被上传";
                //UPLOAD_ERR_NO_FILE
                break;
            case 6:
                $mes = "没有找到临时目录";
                //UPLOAD_ERR_NO_TMP_DIR
                break;
            case 7:
                $mes = "文件不可写";
                //UPLOAD_ERR_CANT_WRITE;
                break;
            case 8:
                $mes = "由于PHP的扩展程序中断了文件上传";
                //UPLOAD_ERR_EXTENSION
                break;
        }
    }
    return $mes;
}
function thumb($filename, $destination = null, $dst_w = null, $dst_h = null, $isReservedSource = true, $scale = 0.5)
{
    //list()函数为里面的元素赋上数组中的值,getimagesize ( string $filename [, array &$imageinfo ] )获取图像的大小,若没有有效信息,返回false
    list($src_w, $src_h, $imagetype) = getimagesize($filename);
    //设置默认缩放比例
    //$scale = 0.5;
    //判断是否设置缩放比
    if (is_null($dst_w) || is_null($dst_h)) {
        $dst_w = ceil($src_w * $scale);
        $dst_h = ceil($src_h * $scale);
    }
    //image_type_to_mime_type()函数判断一个imagetype常量的MIME类型
    //MIME 消息能包含文本、图像、音频、视频以及其他应用程序专用的数据。
    //返回值类似:IMAGETYPE_GIF 对应 image/gif;IMAGETYPE_JPEG对应image/jpeg.
    $mime = image_type_to_mime_type($imagetype);
    //echo $mime;这里输出image/jpeg
    //替换mime数据里的/为createfrom
    //创建画布资源,原句为:$src_image = imagecreatefromjpeg,这里因为是jpeg所以写formjpeg,若是gif则为creategif
    //这里函数用替换法来灵活的确定创建什么样子的画布把image/jpeg变成imagecreatejpeg
    $createFun = str_replace("/", "createfrom", $mime);
    //创建一个JPEG图像并保存,原句为:imagejpeg()
    //imagejpeg(resource $image[, string $filename [, int $quality ]] )函数以$filename问文件名创建一个JPEG图像,输出图像至浏览器或文件中,若有文件名则到文件中
    //这里函数用替换法来灵活确定输出什么样子的图片,把image/jpeg变成imagejpeg
    $outFun = str_replace("/", null, $mime);
    //图片资源赋值给$src_image,即imagecreatejpeg出来的内容赋值给$src_image
    $src_image = $createFun($filename);
    //imagecreatetruecolor()创建一个真彩色图像
    $dst_image = imagecreatetruecolor($dst_w, $dst_h);
    //将一幅图像中的一块正方形区域拷贝到另一个图像中,平滑的插入像素值,因此,尤其是,减小了图像的大小而仍然保持了极大的清晰度。
    //这里将$src_image插入$dst_image中
    imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
    //判断存储路径是否存在,dirname() 函数返回路径中的目录部分。
    if ($destination && !file_exists(dirname($destination))) {
        mkdir(dirname($destination), 0777, true);
    }
    //生成唯一的文件名
    $dstFilename = $destination == null ? getUniName() . "." . getExt($filename) : $destination;
    //存储文件至文件夹中
    $outFun($dst_image, $dstFilename);
    imagedestroy($src_image);
    imagedestroy($dst_image);
    //isReservedSource,判断是否保留原目录里的原文件,这里预设了true,所以不删除
    if (!$isReservedSource) {
        //unlink() 函数删除文件。
        unlink($filename);
    }
    return $dstFilename;
}
Example #13
0
    return strtolower(pathinfo($filename, PATHINFO_EXTENSION));
}
function getUniName()
{
    return md5(uniqid(microtime(true), true));
}
$imagePath = realpath('image.jpg');
//$image = new Imagick('image.jpg');
$image = new Imagick($imagePath);
// If 0 is provided as a width or height parameter,
// aspect ratio is maintained
//$image->thumbnailImage(100, 100);
$image->thumbnailImage(50, 0);
$savePath = "./first/second";
//$realpath1 = realpath($savePath);
//echo $realpath;
//exit;
if (!file_exists($savePath)) {
    if (!mkdir($savePath, 0777, true)) {
        return false;
    }
    chmod($savePath, 0777);
}
$ext = getExt($imagePath);
$uniName = getUniName();
$destination = $savePath . '/' . $uniName . '.' . $ext;
//echo $destination;
//copy($image->getImageBlob(),$destination);
$image->writeImage($destination);
header('Content-type: image/jpeg');
echo $image->getImageBlob();
Example #14
0
function uploadFile($fileInfo, $path = './uploads/file')
{
    //判断错误号
    if ($fileInfo['error'] === UPLOAD_ERR_OK) {
        $ext = getExt($fileInfo['name']);
        //$path='./uploads/file';
        if (!file_exists($path)) {
            mkdir($path, 0777, true);
            chmod($path, 0777);
        }
        $uniName = getUniName();
        $destination = $path . '/' . $uniName . '.' . $ext;
        if (!move_uploaded_file($fileInfo['tmp_name'], $destination)) {
            $res['mes'] = $fileInfo['name'] . '文件移动失败';
        }
        $res['mes'] = $fileInfo['name'] . '上传成功';
        $res['dest'] = $destination;
        return $res;
    } else {
        //匹配错误信息
        switch ($fileInfo['error']) {
            case 1:
                $res['mes'] = '上传文件超过了PHP配置文件中upload_max_filesize选项的值';
                break;
            case 2:
                $res['mes'] = '超过了表单MAX_FILE_SIZE限制的大小';
                break;
            case 3:
                $res['mes'] = '文件部分被上传';
                break;
            case 4:
                $res['mes'] = '没有选择上传文件';
                break;
            case 6:
                $res['mes'] = '没有找到临时目录';
                break;
            case 7:
            case 8:
                $res['mes'] = '系统错误';
                break;
        }
        return $res;
    }
}
Example #15
0
function upload($fileInfo, $uploadPath = 'uploads', $flag = true, $allowExt = array('jpeg', 'jpg', 'png', 'gif'), $maxSize = 2097152)
{
    // 1.接收数据
    // $fileInfo=$_FILES['face'];
    // 2.判断错误信息
    if ($fileInfo['error'] != 0) {
        // 匹配错误信息
        switch ($fileInfo['error']) {
            case 1:
                $mes = '超过了PHP配置文件upload_max_filesize选项的值';
                break;
            case 2:
                $mes = '超过了表单MAX_FILE_SIZE选项的值';
                break;
            case 3:
                $mes = '文件部分被上传';
                break;
            case 4:
                $mes = '没有选择上传文件';
                break;
            case 6:
            case 7:
            case 8:
                $mes = '系统错误';
                break;
        }
        exit($mes);
    }
    // 3.检测上传文件大小
    // $maxSize=2*1024*1024;//允许上传文件的最大值
    if ($fileInfo['size'] > $maxSize) {
        exit('上传文件过大');
    }
    // 4.检测上传文件的类型
    // $allowExt=array('jpeg','jpg','png','gif');//允许上传文件的类型
    $ext = getExt($fileInfo['name']);
    if (!in_array($ext, $allowExt)) {
        exit('非法文件类型');
    }
    // 5.检测是否是真实图片
    // $flag=true;//默认检测
    if ($flag) {
        if (!getimagesize($fileInfo['tmp_name'])) {
            exit('文件不是真实图片');
        }
    }
    // 6.检测是否是通过HTTP POST方式上传上来的
    if (!is_uploaded_file($fileInfo['tmp_name'])) {
        exit('文件不是通过HTTP POST方式上传上来的');
    }
    // 7.开始移动文件
    // $uploadPath='uploads';
    // 检测目录是否存在,不存在则创建
    if (!file_exists($uploadPath)) {
        mkdir($uploadPath, 0777, true);
    }
    $uniName = getUniName() . '.' . $ext;
    $dest = $uploadPath . '/' . $uniName;
    if (!@move_uploaded_file($fileInfo['tmp_name'], $dest)) {
        exit('文件移动失败');
    }
    return array('dest' => $dest, 'size' => $fileInfo['size'], 'type' => $fileInfo['type']);
}