2017-01-02 71 views
0

我收到此錯誤嘗試將圖像上傳到文件夾,第23行拒絕move_uploaded_file權限。應該是什麼問題?我有下面的表格,邏輯和顯示它的頁面。謝謝!第23行拒絕move_uploaded_file權限

<?php 
    include("../views/post_form.php"); 
    require("../includes/include.php"); 
    require("../includes/sess_n.php"); 

    if ($_SERVER["REQUEST_METHOD"]== "POST") 
    { 
     $usertext = $_POST["usertext"]; 
     $image = $_FILES['image']['name']; 
     $talent =$_POST["talenttype"]; 

     if(empty($usertext) || empty($image)|| empty($talent)) 
     { 
      die(); 
     } 

     $id = $_SESSION["id"]; 

     $folder ="images/".basename($_FILES['image']['name']); 

     move_uploaded_file($_FILES['image']['tmp_name'],$folder) ; 

     $query = mysqli_query($link,"SELECT * FROM `upload` WHERE id = '$id'"); 

     $upload = mysqli_query($link,"INSERT INTO `upload` (description,image,talent,folder) VALUES('$usertext','$image','$talent','$folder ')"); 
    } 





    ?> 

要顯示,我希望將照片保存到文件夾,而不是保存。我使用blob方法不插入到數據庫中。

<?php 
     include("../views/feeds_form.php"); 
     require("../includes/include.php"); 
     require("../includes/sess_n.php"); 


      $query = mysqli_query($link,"SELECT * FROM `upload` "); 

      if ($query === false) 
      { 
       die(); 
      } 

      echo '<table>'; 

      while ($run = mysqli_fetch_assoc($query)) 
      { 
       echo '<tr>'; 
       echo '<td>';?> <img src =" <?php echo $run["image"]; ?>" height=100 width=100> <?php echo '<td>'; 
       echo '<td>'; echo $run["description"]; echo '<td>'; echo $run["folder"];echo '<td>'; 
       echo '</tr>'; 
      } 

      echo '</table>'; 
    ?> 

表格在這裏。

<?php 

include("../public/header.php"); 
?> 

<div> <title>post</title></div> 
<style> 
.form-inline 
{ 
    text-align: center; 
    margin-bottom: 50px; 
} 

</style> 


<script type="text/javascript"> 
function validate(){ 

    var usertext = document.getElementById("usertext"); 
    var talent = document.getElementById("talenttype"); 
    var image = document.getElementById("image"); 


    if (usertext.value === "" && talent.value === "" && image.value ==="") 
    { 
    alert("Field Must Not be Empty"); 
    } 
} 


</script> 


<form class="form-inline" method ="POST" action ="post.php" enctype="multipart/form-data" onsubmit= "return validate();"> 
    <div class="form-group"> 
    <label class="sr-only" for="exampleInputEmail3"> </label> 
    <textarea class="form-control" id = "usertext" name ="usertext" rows="5" placeholder="Describe Person Here"></textarea> <br><hr> 
    <label class="sr-only" for="exampleInputEmail3"></label><br> 
     <div class="form-group"> 
    <label for="exampleInputPassword1"></label> 
    <input type="file" class="form-control" id = "image" id="exampleInputPassword1" name="image" placeholder="image"> 
    </div> <br><br><br> <hr> 
    <div class="form-group"> 
    <label for="exampleInputPassword1"></label> 
    <input type="text" class="form-control" id = "talenttype" id="exampleInputPassword1" name = "talenttype" placeholder="Talent-Type"><br><br> 
    </div> <hr> 
    <div> 
    <button type="submit" name ="post" class="btn btn-default">Post</button><br> 
    </div> 
    </div> 

</form> 




<?php 
include("../public/footer.php"); 
?> 
+1

許可,意味着你的文件夾'images'沒有寫權限,以便其權限更改爲077 –

+1

你是爲[** SQL注入**](HTTPS大開:// www.owasp.org/index.php/SQL_Injection)。您需要使用準備好的語句,而不是將變量連接到查詢中。請參閱[如何防止PHP中的SQL注入?](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1)。 –

+0

你使用什麼操作系統? – funsholaniyi

回答

0

問題在於httpd進程所有者沒有映像文件夾的寫入權限。您可以:

  • 將該文件夾下載到PHP的用戶併爲所有者設置寫入權限;或
  • 你讓777:每個人都有讀,寫&執行權限

而且這不是一個好主意,做寫權限全球

+0

這就是問題所在。謝謝 –

+0

如果有幫助請標記爲答案 –

0

我會說,

打開終端 cd到文檔根目錄

鍵入此命令具有超級用戶權限

chmod 775 -R/

希望它有助於否認