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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$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));

 

 

 

posted @   ma_fighting  阅读(519)  评论(0编辑  收藏  举报
编辑推荐:
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
阅读排行:
· 手把手教你更优雅的享受 DeepSeek
· AI工具推荐:领先的开源 AI 代码助手——Continue
· 探秘Transformer系列之(2)---总体架构
· V-Control:一个基于 .NET MAUI 的开箱即用的UI组件库
· 乌龟冬眠箱湿度监控系统和AI辅助建议功能的实现
历史天气查
点击右上角即可分享
微信分享提示