zoukankan      html  css  js  c++  java
  • 关于PHP接收文件的资料

    (一)
    <?php
    $base_path = "./upload/"; // 接收文件目录
    $target_path = $base_path . basename ( $_FILES ['uploadfile'] ['name'] );
    if (move_uploaded_file ( $_FILES ['uploadfile'] ['tmp_name'], $target_path )) {
        $array = array (
                "code" => "1",
                "message" => $_FILES ['uploadfile'] ['name']
        );
        echo json_encode ( $array );
    } else {
        $array = array (
                "code" => "0",
                "message" => "There was an error uploading the file, please try again!" . $_FILES ['uploadfile'] ['error']
        );
        echo json_encode ( $array );
    }
    ?>
    (二)
        <?php  
        // array for JSON response  
         
        //此处需要将数据库名和表明还有密码做相应修改,改成你自己的 
        $con = mysql_connect("localhost","root",null); 
        if (!$con) { 
        die('Could not connect:'.mysql_error() ); 
        } 
        mysql_select_db("a0722152915", $con); 
         
         
         
         
        $response = array();  
        include("conn.php");  
        // check for required fields  
        if (isset($_POST['time']) && isset($_POST['lat']) && isset($_POST['lon'])&& isset($_POST['encyptiontype'])&& isset($_POST['rssi'])&& isset($_POST['name'])) {  
        $time = $_POST['time'];  
        $lat = $_POST['lat'];  
        $lon = $_POST['lon'];  
        $encyptiontype = $_POST['encyptiontype'];  
        $rssi = $_POST['rssi'];  
        $name = $_POST['name'];  
        $result = mysql_query("INSERT INTO wifi_state(time, lat, lon,encyptiontype,rssi,name) VALUES('$time', '$lat', '$lon','$encyptiontype','$rssi','$name')");  
        echo $result;  
        // check if row inserted or not  
        if ($result) {  
        // successfully inserted into database  
        $response["success"] = 1;  
        $response["message"] = "Product successfully created.";  
        // echoing JSON response  
        echo json_encode($response);  
        } else {  
        // failed to insert row  
        $response["success"] = 0;  
        $response["message"] = "Oops! An error occurred.";  
        // echoing JSON response  
        echo json_encode($response);  
        }  
        } else {  
        // required field is missing  
        $response["success"] = 0;  
        $response["message"] = "Required field(s) is missing";  
        // echoing JSON response  
        echo json_encode($response);  
        }  
        ?>

  • 相关阅读:
    Django模板
    创建我的第一个django项目
    python django环境配置与安装
    python第九期学习笔记(装饰器进阶)
    python第九期学习笔记(十二)(线程)
    python第九期学习笔记(装饰器)
    python第九期学习笔记(闭包)
    python第九期学习笔记(十二)(面向对象)
    python第九期学习笔记(十一)(面向对象)
    python第九期学习笔记(十)(模块)
  • 原文地址:https://www.cnblogs.com/ck-999/p/5369305.html
Copyright © 2011-2022 走看看