跟踪function()
搜索(filemanager/upload.php)
在代码中发现,上传成功后,会传回JSON信息数据,于是最后找到方法是
$upload_handler = new UploadHandler($uploadConfig, true, $messages);
同时大叔发现upload.php自己没有uploadhandler()方法,但是引入入
require(\'UploadHandler.php\'); $messages = null;
于是乎
搜索(filemanager/UploadHandler.php)
在代码中发现UploadHandler{}是个大类,只能继续在里面找方法
发现判断尺寸真实有效时,会判断是否为post传值,如果是会将数据进行操作
if ($initialize) { $this->initialize(); } protected function initialize() { switch ($this->get_server_var(\'REQUEST_METHOD\')) { ... case \'POST\': $this->post($this->options[\'print_response\']); break; ... } }
于是查看post()方法,发现handle_file_upload()方法中放进了所有的POST图片信息
public function post($print_response = true) { ... $files[] = $this->handle_file_upload( isset($upload[\'tmp_name\']) ? $upload[\'tmp_name\'] : null, $file_name ? $file_name : (isset($upload[\'name\']) ? $upload[\'name\'] : null), $size ? $size : (isset($upload[\'size\']) ? $upload[\'size\'] : $this->get_server_var(\'CONTENT_LENGTH\')), isset($upload[\'type\']) ? $upload[\'type\'] : $this->get_server_var(\'CONTENT_TYPE\'), isset($upload[\'error\']) ? $upload[\'error\'] : null, null, $content_range ); ... }
查看handle_file_upload()方法,终于找到了move_uploaded_file()方法,按方法逻辑和两个参数的值,他正在将post临时图片上传至程序图片文件夹内。
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { ... move_uploaded_file($uploaded_file, $file_path); ... }
于是大叔决定在该函数下增加一个加水印的方法,让他可以对上传的每一张图片操作,但是无论怎么写,只要一有操作方法就会各种提示错误,于是只能放弃。
这时大叔记起,插件的缩略并不是直接生成的,他的流程是:
上传图片成功->重新刷新dialog.php->判断有新图片存在->自动生成缩略图
于是大叔开始查看插件自动生成缩略图的方法,结果一找就找到了,他正好就在上传图片的方法下面。
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { ... if ($this->is_valid_image_file($file_path)) { $this->handle_image_file($file_path, $file); } ... }
于是大叔将水印方法写在下面
if ($this->is_valid_image_file($file_path)) { //自动生成缩略图 $this->handle_image_file($file_path, $file); //===========================水印图片.S $src_path = \'mark.png\'; //水印图片 $dst_path = $file_path; //需要添加水印图片 //创建图片的实例 $dst = imagecreatefromstring(file_get_contents($dst_path)); $src = imagecreatefromstring(file_get_contents($src_path)); //获取水印图片的宽高 list($src_w, $src_h) = getimagesize($src_path); //获取要加水印图片的宽高 list($dst_w, $dst_h) = getimagesize($dst_path); //将水印图片复制到目标图片上,最后个参数50是设置透明度,这里实现半透明效果 //imagecopymerge($dst, $src, 10, 10, 0, 0, $src_w, $src_h, 50); //如果水印图片本身带透明色,则使用imagecopy方法 imagecopy($dst, $src, ($dst_w - $src_w - 10), ($dst_h - $src_h - 10), 0, 0, $src_w, $src_h); //输出图片 list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path); switch ($dst_type) { case 1://GIF header(\'Content-Type: image/gif\'); imagegif($dst); break; case 2://JPG header(\'Content-Type: image/jpeg\'); imagejpeg($dst); break; case 3://PNG header(\'Content-Type: image/png\'); imagepng($dst); break; default: break; } //清除图片缓存 imagedestroy($dst); imagedestroy($src); //===========================水印图片.E }
上传邓妞...
测试成功!
感谢: