2015-10-19 61 views
0

我有一個表單,我一直在用我的本地主機開發這個網站,它工作的很完美。但是當我將這些文件移動到我的專用服務器時,在我提交表單時不再獲得任何值。我已經縮小到兩件事。我的服務器在被提交的表單上有限制的配置,但是我沒有使用全局變量來獲取值,所以不應該是問題,或者服務器上的php比較老,不允許我提交我找到的服務器版本的值出局是< 5.6。這裏是我的表單代碼:服務器沒有獲取表單值

<form id="company-form" action="scripts/create-library.php" method="post" enctype="multipart/form-data"> 
<button id="hide-form"><img src="images/minus.png"/></button> 
<h3>Add Library Item Form</h3> 
<input class="c-name" type="text" name="file-display-name" placeholder="File Display Name"/> 
<select class="companies-dd" name="companies"> 
    <?php 
     require_once("../../scripts/connection.php"); 

     // Select all companies and related data 
     $sql = "SELECT company_id, company FROM companies ORDER BY company_id"; 
     $stmt = $conn->prepare($sql); 
     $stmt->execute(); 
     $stmt->bind_result($c_id, $c); 
     while($stmt->fetch()){ 
      echo "<option value='".$c_id."'>".$c."</option>"; 
     } 
    ?> 
</select> 
<select class="companies-dd" name="library-cats"> 
    <?php  
     // Select all companies and related data 
     $sql = "SELECT library_category_id, library_category FROM library_categories ORDER BY library_category_id"; 
     $stmt = $conn->prepare($sql); 
     $stmt->execute(); 
     $stmt->bind_result($l_id, $l); 
     while($stmt->fetch()){ 
      echo "<option value='".$l_id."'>".$l."</option>"; 
     } 
     $conn->close(); 
    ?> 
</select> 
<input id="uploadFile" class="image-name" type="text" name="library-file-name" placeholder="No Logo File Chosen" disabled="disabled"/> 
<input id="uploadBtn" type="file" name="library-file"/> 
<input type="submit" value="Create Item"/> 
</form> 

這是通過按鈕點擊ajax調用添加頁面。

那時,我在提交表格後運行的腳本是

<?php 
session_start(); 
ini_set('display_errors',1); 
error_reporting(-1); 

$display = trim($_POST["file-display-name"]); 
$company = trim($_POST["companies"]); 
$lib_cat = trim($_POST["library-cats"]); 

if(empty($display) || empty($company) || empty($lib_cat)){ 
    $_SESSION["errormsg"] = "Required information is missing please fill out all required fields."; 
    header("Location: ../library.php"); 
} 
else{ 
    $file_name = $_FILES['library-file']['name']; 
    $tmp_name = $_FILES['library-file']['tmp_name']; 
    $file_size = $_FILES['library-file']['size']; 
    $file_type = $_FILES['library-file']['type']; 

    $fp = fopen($tmp_name, 'r'); 
    $content = fread($fp, filesize($tmp_name)); 
    $content = base64_encode($content); 
    fclose($fp); 

    if(!get_magic_quotes_gpc()){ 
     $file_name = addslashes($file_name);  
    } 

    if(empty($content)){ 
     $_SESSION["errormsg"] = "Required information is missing please fill out all required fields (File)."; 
     header("Location: ../library.php"); 
    } 
    else{ 
     require_once("connection.php"); 

     // Insert the logo into the companies photo table 
     $sql = "INSERT INTO library_items(filename, mime_type, file_size, file_item, display_name, company_id, library_category_id) VALUES(?,?,?,?,?,?,?)"; 

     $stmt = $conn->prepare($sql); 
     $stmt->bind_param('sssssss', $file_name, $file_type, $file_size, $content, $display, $company, $lib_cat); 
     if(!$stmt->execute()){ 
      $_SESSION["errormsg"] = "Failed to add library item: ".mysqli_error(); 
      header("Location: ../library.php"); 
     } 
    } 
    unset($_SESSION["errormsg"]); 

    $_SESSION["successmsg"] = "Library Item successfully added into the database."; 
    header("Location: ../library.php"); 
} 

?>

它給我的變量說他們是不確定的指標對錶格名稱錯誤。

我已閱讀其他帖子,但沒有人幫助過我。有沒有我沒有看到或我必須在我的服務器上更改以供我使用?

+0

[PHP:「Notice:Undefined variable」和「Notice:Undefined index」]的可能重複(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined- index) – cmorrissey

+0

你的html中的標籤在哪裏? –

+0

那不是同一類型的問題。我知道未定義的索引意味着什麼以及它發生的原因。我不知道的是爲什麼它在我的本地主機上工作,並且這些值是正確的,並且確實有值,表明它們沒有在提交時傳遞給腳本。 –

回答

0

那麼它看起來像我用來測試上傳和顯示的兩個文件在我下載它們時最終損壞了。這導致服務器拋出並錯誤地指出文本超出了US-ASCII範圍。由於無法顯示,因此未傳輸任何表單值。這是我曾經遇到的最奇怪的錯誤,我想我將不得不開始測試我的PDF錯誤也。

相關問題