php

$json_result ['status'] = 0;

$path = '../upfile';

$json_result ['status'] = 0;

$json_result ['successmsg'] = '上传失败';

if (isset ( $_FILES ['image'] )) {

    $upfile = 'upfile/' . $_FILES ['image'] ['name'];

    if (! @file_exists ( $path )) {

        @mkdir ( $path );

    }

    $result = @move_uploaded_file ( $_FILES ['image'] ['tmp_name'], $upfile );

    if (! $result) {

        $json_result ['status'] = 0;

        $json_result ['successmsg'] = '上传失败';

        $json_result ['datas'] = array ('savePath' => $upfile );

        exit ( json_encode ( $json_result ) );

    }

}

 

$json_result ['successmsg'] = '上传成功';

$json_result ['status'] = 1;

$json_result ['datas'] = array ('savePath' => "http://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/mafeng/".$upfile );

print_r(json_encode($json_result));

 

原文地址:https://www.cnblogs.com/mafeng/p/5890334.html