码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-09-20 21:20:24      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:

$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 - 上传图片之痛(建文件夹)

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!