首页 > 代码库 > php - 上传图片之痛(建文件夹)

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));

 

技术分享 

 

php - 上传图片之痛(建文件夹)