javascript - php脚本在系统本地工作但不在服务器上工作

标签 javascript java php html css

请帮我检查下面的代码,看看哪里有错误,因为代码在我的系统上本地运行,但在服务器上运行不正常。它到达了将图像移动到文件夹的地步,但数据没有移动到数据库。我已经检查了又检查,但不能真正将我的手放在错误上,我很快就会非常感谢某种帮助。谢谢。

<?php


include_once("../php/db_connection.php");
include_once("php/admin_session.php");

?>
<?php
 // ADD NEW PROPERTY
 $error_msg = '';
if(isset($_POST['title'])){
$title = $_POST['title'];
$names = $_POST['name'];
$description = $_POST['description'];
$price = $_POST['price'];
$category = $_POST['category'];
$location = $_POST['location'];
$map = $_POST['map'];
$img = "../rent_images/$names";

if(isset($_FILES['product_image'])){
    foreach($_FILES['product_image']['tmp_name'] as $key => $tmp_name ){
        $file_name = $key.$_FILES['product_image']['name'][$key];
        $file_size =$_FILES['product_image']['size'][$key];
        $file_tmp =$_FILES['product_image']['tmp_name'][$key];
        $file_type=$_FILES['product_image']['type'][$key];  
        if($file_size > 2097152){
            $error_msg ='File size must be less than 2 MB';
        }       
        $desired_dir=$img;
        if(empty($error_msg)==true){
            if(is_dir($desired_dir)==false){
                mkdir("$desired_dir", 0755);        // Create directory if    it does not exist
            }
                if(is_dir("$desired_dir/".$file_name)==false){
                move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
                }
                else{                                  // rename the file if another one exist
                $new_dir="$desired_dir/".$file_name.time();
                 rename($file_tmp,$new_dir) ;               
                }
        }
    }
    $sql_addProduct = mysqli_query($connection, "INSERT INTO rents(id,title,name,description,price,category,location,map,date_added) VALUES('','$title','$names','$description','$price','$category','$location','$map',now())");
    if(!$sql_addProduct){
        $error_msg = '<div class="atention">Couldn\'t upload the images or property details, please try again</div>';
    }else{
       header("location: property_list.php");
       exit();
    }
}
}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Admin Panel</title>
<link rel="stylesheet" type="text/css" href="style/bootstrap.css">
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen"/>

<script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript">
    $(function(){
        var pull = $('#pull');
        menu = $('nav ul');
        menuHeight = menu.height();

        $(pull).on('click', function(e){
            e.preventDefault();
            menu.slideToggle();
        });
    });
</script>
<script type="text/javascript">
    $(window).resize(function(){
        var w = $(window).width();
        if(w > 320 && menu.is(':hidden')){
            menu.removeAttr('style');
        }
    });
</script>
</head>

<body>
<div class="container">
<div>
    <?php include_once("template/header.php"); ?>
</div>
<div class="row">
    <p><a href="property_list.php"> Click Here Update Property</a></p>
    <table width="100%" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td valign="top" width="100%">
                    <section id="main_content">
                        <h1>Add Product</h1>
                        <?php echo $error_msg; ?>
                        <form action="" method="post" enctype="multipart/form-data">
                            <input type="text" class="input-login" name="title" placeholder="Title" maxlength="100"><br><br>
                            <input type="text" class="input-login" name="name" placeholder="Name" maxlength="100"><br><br>
                            <textarea cols="50" rows="10" name="description" placeholder="Detailed description"></textarea><br><br>
                            <input type="text" class="input-login" name="price" placeholder="Price" maxlength="15"><br><br>
                            <input name="category" class="input-login" placeholder="Category" maxlength="50"><br><br>
                            <input name="location" class="input-login" placeholder="location" maxlength="50"><br><br>
                            <textarea cols="50" rows="10" name="map" class="input-login" placeholder="Insert Google map address"></textarea><br><br>
                            <input type="file" name="product_image[]" multiple title="Select property images"><br>
                            <br/>
                            <button id="submitBTN">Add Product</button>
                        </form>
                    </section>
                </td>
            </tr>
        </table>
</div>
<div>
    <?php include_once("../template/footer.php"); ?>
</div>
</div>
</body>
</html>

最佳答案

看起来您的 db-connection 或 admin_session 包含错误。假设您将它们放在同一个文件夹中。

关于javascript - php脚本在系统本地工作但不在服务器上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43380714/

相关文章:

php - MySQL自定义全局定义变量

javascript - 输入的每个更改都作为数据单独存储(例如 : "t", "te"、 "tes"、 "test"而不是只有 "test")

javascript - 如何识别作用域对象是否有值

java - Spark 中聚合键、值对

java - 删除两个字符之间的子字符串

php - 将 PHP 和 MySQL 编译为独立的 Windows 或 Linux 应用程序

php - 在laravel中使用 "store function"中的外键将数据存储到多个表

javascript - 如何用angular2和typescript隐藏android actionbar?

javascript - 如何以编程方式检查按钮单击上的真正 extjs 树面板复选框?

java - 如何在Android中进行Json解析