0

I'm getting this error trying to upload image to a folder, move_uploaded_file permission denied on line 23. What should be the problem? I have the form below, the logic and the page to display it. Thanks!

  <?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 ')");
    }





    ?>

To display, I want the photos to be save to the folder, not saving. I used blob method not inserting into the database.

    <?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>';
     ?>  

The form here.

<?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");
?>
Panda
  • 6,955
  • 6
  • 40
  • 55

2 Answers2

0

Issue is that httpd process owner doesn't have write permission for images folder. You can either:

  • chown the folder to PHP's user and set write permission for owner; or
  • You make it 777: everybody has Read, Write & Execute permission

Also it is not a good idea to do write permission globally

skull_king
  • 70
  • 8
0

I'd say,

Open your terminal cd to the document root directory

type this command with super user privileges

chmod 775 -R /

Hope it Helps

funsholaniyi
  • 435
  • 2
  • 12