找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 57|回复: 5

(版主慢删)万能的loc求助php大佬

[复制链接]

8

主题

25

回帖

94

积分

注册会员

积分
94
发表于 2018-6-14 10:28:19 | 显示全部楼层 |阅读模式
本帖最后由 seafood_to 于 2018-6-14 10:38 编辑

学习php但是网站的一个图片上传功能用不了
页面显示上传成功函数也不报错但是目标文件就是不存在
求助php大佬!!!
表单提交部分代码:
" method="post" enctype="multipart/form-data">
......

......
接收上传部分代码:
$image = $_FILES['pic']['tmp_name'];
......
if(!empty($image)){
        $path = PATH.'upload/goods/';
        注:define('PATH', str_replace('\\','/',dirname(__FILE__)).'/../');  
        $filename = upload('pic',$path);
        $path = PATH.'upload/goods/'.$filename;
        $newname = zoom($path,200,200);
        unlink($path);
}
函数代码:
function upload($field,$path){
        if($_FILES[$field]['error'] != 0) exit('上传出错');
        list($maintype,$subtype) = explode('/',$_FILES[$field]['type']);
        if($maintype != 'image') exit('请上传图片');
        if($subtype == 'jpeg') $subtype = 'jpg';
        $newfile = md5(uniqid()).'.'.$subtype;
        $newpath = rtrim($path,'/').'/'.$newfile;
        $res = move_uploaded_file($_FILES[$field]['tmp_name'],$newpath);
        if($res){
            return $newfile;
        }else{
            return '上传失败';
        }
}
function zoom($path,$width=200,$height=200){

        $info = getimagesize($path);

        if(!$info) exit('请处理图片');
        $arr = explode('/',$info['mime']);
        $ext = $arr[1];

        $create = 'imagecreatefrom'.$ext;
        $save = 'image'.$ext;
        
        list($t_w,$t_h) = $info;

        $des_w = $width;
        $des_h = $des_w * ($t_h / $t_w);
        if($des_h >  $height){
            $des_h = $height;
            $des_w = $height * ($t_w / $t_h);
        }else{
            $des_w = $width;
            $des_h = $des_w * ($t_h / $t_w);
        }
        $huabu = imagecreatetruecolor($width,$height);
        $white = imagecolorallocate($huabu, 255, 255, 255);
        imagefill($huabu, 0, 0, $white);
        $meizi = $create($path);
        $hua_x = ($width - $des_w) / 2;
        $hua_y = ($height - $des_h) / 2;

        imagecopyresampled($huabu,$meizi, $hua_x,$hua_y, 0,0, $des_w,$des_h, $t_w,$t_h);
        if($ext == 'jpeg') $ext = 'jpg';
        $filename = basename($path);
        $filename = substr($filename,0,strrpos($filename,'.'));
        $newname =$filename.'.'.$ext;
        $savepath = rtrim(dirname($path),'/').'/'.$newname;
        $save($huabu,$savepath);
        imagedestroy($huabu);
        imagedestroy($meizi);
        return $newname;
}
上传的文件夹goods是存在的,函数也返回了新的文件名newfile但是上传的文件就是找不到,用的lnmp.org一键包的lamp文件夹权限WWW:755
回复

使用道具 举报

576

主题

4642

回帖

1万

积分

论坛元老

积分
11076
发表于 2018-6-14 10:30:06 | 显示全部楼层
不如直接上传php文件方便
回复

使用道具 举报

8

主题

25

回帖

94

积分

注册会员

积分
94
 楼主| 发表于 2018-6-14 10:41:58 | 显示全部楼层

今晚我是你的 发表于 2018-6-14 10:30

不如直接上传php文件方便

其他代码多又乱,就把相关的代码都剪出来了
回复

使用道具 举报

8

主题

25

回帖

94

积分

注册会员

积分
94
 楼主| 发表于 2018-6-14 10:30:00 | 显示全部楼层
暖贴
回复

使用道具 举报

25

主题

682

回帖

1513

积分

金牌会员

积分
1513
发表于 2018-6-14 10:59:55 | 显示全部楼层
看样子像是zoom函数直接是覆盖掉的原始文件,然后后面的unlink函数又删掉文件了。。。
回复

使用道具 举报

16

主题

151

回帖

376

积分

中级会员

积分
376
发表于 2018-6-14 12:12:48 | 显示全部楼层
膜拜技术大佬们~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Discuz! X

GMT+8, 2025-3-6 03:18 , Processed in 0.021775 second(s), 4 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表