/** * 存储上传的文件 * $subpath 为相对于框架文件夹的目录<br/> * 如果没有访问权限的限制,建议存放在pub文件夹下<br/> * $subpath 不要包含文件后缀,方法会自动根据上传问价的后缀添加<br/> * 如:pub/user1/head,其中head为文件名如上传图片为gif格式则为head.gif<br/> * 一般无需调用,只在特殊指定上传控件的url参数时使用 * @param string $subpath 相对网站目录的路径 */ static function save_upload_file($subpath, $funupload = null, $funcut = null, $isfile = false) { //临时目录清空 if (trim(Conf::$remote_path) != '') { $syspathp = Conf::$local_remote; $STA = Conf::$remote_path; } else { $syspathp = YYUC_FRAME_PATH . YYUC_PUB . '/'; $STA = '/'; } File::clear_dir($syspathp . 'upload/temp/', time() - 86400); File::creat_dir_with_filepath($syspathp . $subpath); if (!empty($_FILES) && isset($_FILES['YYUC_UPLOAD_file'])) { //第一次上传 $thisid = $_POST['YYUC_UPLOAD_ID']; $thissize = intval($_SESSION['YYUC_last_upsizelimit']) * 1000; if ($thissize == 0) { $thissize = intval($_POST['YYUC_UPLOAD_SIZE']) * 1000; } $f = $_FILES['YYUC_UPLOAD_file']; if ($f['size'] > $thissize) { Response::text('<html><head><script>window.parent.' . $thisid . '=1;window.parent.' . $thisid . '_failure(' . $f['size'] / 1000 . ',2);</script></head><body>1111</body></html>', Mime::$html); } else { if ($isfile) { $filename = $subpath; } else { $path_parts = pathinfo($f['name']); $theoldname = substr($f['name'], 0, strrpos($f['name'], '.')); if (mb_strlen($theoldname) > 12) { $theoldname = mb_substr($theoldname, 0, 10) . '..'; } $oldname = base64_encode($theoldname); $oldname = str_replace('/', 'ITI@I', $oldname); $filename = $subpath . '_' . $oldname . '.' . $path_parts['extension']; } if (stripos($filename, '.php') !== false) { die; } if (!move_uploaded_file($f['tmp_name'], $syspathp . $filename)) { Response::text('<html><head><script>window.parent.' . $thisid . '=1;window.parent.' . $thisid . '_failure("很抱歉上传发生未知错误,请联系平台客服。错误数据:' . $filename . '",4);</script></head><body>1111</body></html>', Mime::$html); } else { if ($funupload !== null) { call_user_func_array($funupload, array($syspathp . $filename)); } Response::text('<html><head><script>window.parent.' . $thisid . '=1;window.parent.' . $thisid . '_success("' . $STA . $filename . '","' . $filename . '");</script></head><body>1111</body></html>', Mime::$html); } } } else { if (Request::post('key')) { //剪切 $filename = Request::post('key'); if (!file_exists($syspathp . $filename)) { return false; } //剪切之后的处理 $img_r = imagecreatefromstring(file_get_contents($syspathp . $filename)); if ($img_r === false) { Response::text('no'); } $dsw = Request::post('w'); $dsh = Request::post('h'); if (Request::post('cw') != '0' && Request::post('ch') != '0') { $dsw = Request::post('cw'); $dsh = Request::post('ch'); } $dst_r = ImageCreateTrueColor($dsw, $dsh); imagecopyresampled($dst_r, $img_r, 0, 0, Request::post('x'), Request::post('y'), $dsw, $dsh, Request::post('w'), Request::post('h')); //$path_parts = pathinfo($filename); $oldnames = substr($filename, 0, strrpos($filename, '.')); $oldnames = explode('_', $oldnames); $oldname = $oldnames[count($oldnames) - 1]; $filename2 = $subpath . '_' . $oldname . '.jpg'; imagejpeg($dst_r, $syspathp . $filename2, 90); if ($filename2 != $filename) { unlink($syspathp . $filename); } if ($funcut !== null) { call_user_func_array($funcut, array($syspathp . $filename2)); } Response::text($filename2); } else { return false; } } return true; }