KunWeb/zciyphp/upload.php
2025-05-16 01:00:48 +08:00

33 lines
1.3 KiB
PHP

<?php
/* =================================================================================
* License: GPL-2.0 license
* Author: 众产® https://ciy.cn/code
* Version: 0.6.10
* =================================================================================*/
namespace ciy;
class upload {
public static function Fileext($filename) {
$name = str_replace('\\', '/', $filename);
$pos = strrpos($name, '/');
$name = (false === $pos) ? $name : substr($name, $pos + 1);
$extfile = strtolower(pathinfo($name, PATHINFO_EXTENSION)); // jpg
$name = substr($name, 0, -strlen($extfile) - 1); //name去掉扩展名
return array($name, $extfile);
}
public static function SaveUploadFile($path, $file, $rep = false) {
if (!$rep) {
if (file_exists(PATH_WEB . 'ud/' . $path))
ciy_ouputJSON(errjson('文件已存在'));
}
$tpath = dirname(PATH_WEB . 'ud/' . $path);
dirmake($tpath);
$tstr = file_get_contents($file['tmp_name']);
if (strpos($tstr, '<?php') !== false)
ciy_ouputJSON(errjson('文件内容不合法'));
move_uploaded_file($file['tmp_name'], PATH_WEB . 'ud/' . $path);
return array('url' => '/' . $path);
}
}