本代码的功能是把你要上传的图片保存到服务器,然后再把当前图重按比例生成一个小的缩略图哦。
if($_FILES['image']['size']){
if($_FILES['image']['type'] == "image/pjpeg"){
$im = @imagecreatefromjpeg($_FILES['image']['tmp_name']);
$n_bmp.='.jpg';
}elseif($_FILES['image']['type'] == "image/x-png"){
$im = @imagecreatefrompng($_FILES['image']['tmp_name']);
$n_bmp.='.png';
}elseif($_FILES['image']['type'] == "image/gif"){
$im = @imagecreatefromgif($_FILES['image']['tmp_name']);
$n_bmp.='.gif';
}
ResizeImage($im,8888,8888,$n_bmp);
ImageDestroy ($im);
$n_tag =1;
}
function Uploadfile($str){
$save_path = './product/';//文件保存目录路径
$ext_arr = array('rar','zip','jpg','gif','png','bmp');//定义允许上传的文件扩展名
$max_size = 1000000;//最大文件大小
$file_rand ='';
$file_ext ='';
@mkdir($save_path, 0777); //更改目录权限
if ($_FILES[$str]['name']) {//有上传文件时
$file_name = $_FILES[$str]['name'];//原文件名
$tmp_name = $_FILES[$str]['tmp_name'];//服务器上临时文件名
$file_size = $_FILES[$str]['size'];//文件大小
if (@is_dir($save_path) === false) {//检查目录
alert("上传目录不存在。",'');
}
if (@is_writable($save_path) === false) {//检查目录写权限
alert("上传目录没有写权限。",'');
}
if (@is_uploaded_file($tmp_name) === false) {//检查是否已上传
alert("临时文件可能不是上传文件。",'');
}
if ($file_size > $max_size) {//检查文件大小
alert("上传文件大小超过限制。",'');
}
$temp_arr = explode(".", $file_name);//获得文件扩展名
$file_ext = array_pop($temp_arr);
$file_ext = trim($file_ext);
$file_ext = strtolower($file_ext);
$file_rand= md5(date("Y-m-d"));
if (in_array($file_ext, $ext_arr) === false) {//检查扩展名
alert("上传文件扩展名是不允许的扩展名。",'');
}
if (move_uploaded_file($tmp_name, $save_path.$file_rand.'.'.$file_ext) === false) {//移动文件
alert("上传文件失败。",'');
}
}
return $save_path.$file_rand.'.'.$file_ext;
}
function ResizeImage($im,$maxwidth,$maxheight,$name){
$width = imagesx($im);
$height = imagesy($im);
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$RESIZEWIDTH=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$RESIZEHEIGHT=true;
}
if($RESIZEWIDTH && $RESIZEHEIGHT){
if($widthratio
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($RESIZEWIDTH){
$ratio = $widthratio;
}elseif($RESIZEHEIGHT){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if(function_exists("imagecopyresampled")){
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
ImageJpeg ($newim,'./product_e/'.$name);
ImageDestroy ($newim);
}else{
ImageJpeg ($im,'./product_e/'.$name);
}
}

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。