請幫助我通過下面的代碼來查看哪裏出現錯誤,因爲代碼在本地系統上工作,但在服務器上工作不正常。它將圖像移動到文件夾,但數據不會移動到數據庫。我已經檢查並檢查過,但不能真正把我的手放在錯誤上,我很快會很感激某種幫助。謝謝。php腳本在系統上本地工作,但不在服務器上
<?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>
你可能有間接的目錄名的問題。 Apache可能正在執行它在不同的目錄 – Forbs
親切膨脹更多請。 – kaybee