HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/sr.dfhtcs.com/duotu.php
 <?php 
 header("Access-Control-Allow-Origin: *"); //解决跨域
 header('Access-Control-Allow-Methods:post');// 响应类型
 date_default_timezone_set('PRC');//获取当前时间
 
  
$month = date('Ym', time());//获取年月
define('BASE_PATH', str_replace('\\', '/', realpath(dirname(__FILE__).'/'))."/");
$dir = BASE_PATH."upload/".$month."/";//判断是否有对应的文件





$file_info = $_FILES['file'];//前端传过来的文件
 $file_error = $file_info['error'];
if (!is_dir($dir)) {//判断目录是否存在
    mkdir($dir, 0777, true);//如果目录不存在则创建目录
};

$arr = array(
'code' => 0,//返回状态
'msg'=> '',//提示消息
'data' =>array(//文件链接
     'src' => "/upload/".$month."/" . time().$_FILES["file"]["name"]
     ),
);

$file = $dir.time().$_FILES["file"]["name"];//上传文件的名字
// var_dump($_FILES["file"]["tmp_name"]);die;
if (!file_exists($file)) {//判断文件中是否有相同的文件
    if ($file_error == 0) {
        if (move_uploaded_file($_FILES["file"]["tmp_name"], $dir.time(). $_FILES["file"]["name"])) {
            $arr['msg'] ="上传成功";
        } else {
            $arr['msg'] = "上传失败";
        }
    } else {
        switch ($file_error) {
            case 1:
           $arr['msg'] ='上传文件超过了PHP配置文件中upload_max_filesize选项的值';
                break;
            case 2:
              $arr['msg'] ='超过了表单max_file_size限制的大小';
                break;
            case 3:
               $arr['msg'] ='文件部分被上传';
                break;
            case 4:
              $arr['msg'] ='没有选择上传文件';
                break;
            case 6:
                $arr['msg'] ='没有找到临时文件';
                break;
            case 7:
            case 8:
               $arr['msg'] = '系统错误';
                break;
        }
    }
} else {
    $arr['code'] ="1";
    $arr['msg'] = "当前目录中,文件".$file."已存在";
}
 echo json_encode($arr);//将遍历好的数组反给前端