swoole文件上传代码


<?php
$http = new swoole_http_Server("0.0.0.0", 9501);
 
$http->on('request', function ($request, $response) use($http) {
    if($request->server['request_method'] != 'GET'){
        echo'提交方式不对'.PHP_EOL;

        return ;
    }
    $file = $request->files['files'];
    $file_name = $file['name'];
    $file_tmp_path = $file['tmp_name'];
    $uplod_path = __DIR__.'/uplode/';
    if(!file_exists($uplod_path)){
        mkdir($uplod_path);
    }
    $res = move_uploaded_file($file_tmp_path,$uplod_path . $file_name);//函数将上传的文件移动到新位置。
    if($res){
        $response->end("<h1>Hello Swoole. Upload Success </h1>");
    }
    $response->end("<h1>Hello Swoole. Upload Failed </h1>");
});
$http->start();

 

你可能感兴趣的