简体   繁体   中英

Warning: move_uploaded_file failed to open stream: Permission denied PHP file

I am currently working on a booking system. When the admin logs in he/she has to be able to update data.I am trying to upload an image to update an image but every time I try to do that, I get two warning messages. The following are the warning messages that I receive.

Warning: move_uploaded_file(../production_images/113.jpg): failed to open stream: Permission denied in /home/www/TheatreWebsite/storeadmin/inventory_edit.php on line 87

Warning: move_uploaded_file(): Unable to move '/tmp/phpDt7qFp' to '../production_images/113.jpg' in /home/www/TheatreWebsite/storeadmin/inventory_edit.php on line 87

The following is my PHP code:

        <?php 
        if (isset($_POST['productiontype'])) {
        //$pid = mysql_real_escape_string($_POST['thisID']);
         $pid = mysqli_real_escape_string($db_con,$_POST['thisID']);
        $productionname = mysqli_real_escape_string($db_con,$_POST['productionname']);
        $productiontype = mysqli_real_escape_string($db_con,$_POST['productiontype']);
                     $description =  mysqli_real_escape_string($db_con,$_POST['description']);

                $q1 = "UPDATE Production SET productionname = '$productionname', productiontype='$productiontype', description='$description'  WHERE productionid='$pid'";      $sql = $db_con->query($q1);

            if ($_FILES['filefield']['tmp_name'] != "") {
                // Place image in the folder 
                $newname = "$pid.jpg";
                 echo '<script language="javascript">';
                     //$pid = mysqli_real_escape_string($db_con,$_POST['thisID']);
                        echo "alert('$newname')";
        echo '</script>';
                move_uploaded_file($_FILES['filefield']['tmp_name'], "../production_images/".$newname);
            }
        }
        ?>

        <?php 
        // Gather this product's full information for inserting automatically into the edit form below on page
        if (isset($_GET['pid'])) {
            $targetID = $_GET['pid'];               

            $sql = "SELECT * FROM Production WHERE productionid='$targetID' LIMIT 1";
            $sql = mysqli_query($db_con,$sql);

           $productCount = mysqli_num_rows($sql); // count the output amount
            if ($productCount > 0) {
                while($row =  mysqli_fetch_array($sql,MYSQLI_ASSOC)){ 
                     $pid = $row["productionid"];
                     $productionname = $row["productionname"];
                     $productiontype = $row["productiontype"];
                     $description = $row["description"];                                 
                }
            } else {
                echo "Sorry that Production doesn't exist.";
                exit();
            }
        }
        ?>
        <!DOCTYPE>
        <html>
        <head>
            <title>Inventory Edit</title>
            <link rel="stylesheet" href="css/main_style.css" type="text/css" media="screen"/>
            <style>
            </style>
            </head>
                <div align="right" style="margin-left:30px"> <a href="inventory_list.php#inventoryForm">+ NEW INVENTORY ITEM</a></div>

                    <form action="inventory_edit.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post" >

                    <table width="90%" border="0" cellspacing="0" cellpadding="6">
                      <tr>
                        <td width="20%">Production Name</td>
                        <td width="80%"><label>
                        <input name="productionname" type="text" id="productionname" size="64" value="<?php echo $productionname; ?>"/>
                        </label></td>
                      </tr>
                      <tr>
                        <td>Production Type</td>
                        <td><label>
                       <select name="productiontype" id="productiontype">
                       <option value="<?php echo $productiontype;?>"><?php echo $productiontype;?> </option>
                       <option value="Comedy">Comedy</option> 
                       <option value="Drama">Drama</option>     
                       <option value="Opera">Opera</option>
                       <option value="Romance">Romance</option>
                       <option value="Fantasy">Fantasy</option>
                       <option value="Horror">Horror</option>
                       </select>
                       </label></td>
                      </tr>
                       <tr>
                        <td>Production Description</td>
                        <td><label>
                        <textarea name="description" id="description" cols="64" rows="5"><?php echo $description;?></textarea>
                        </label></td>
                      </tr>
                        <td>Product Image</td>
                        <td><label>
                        <input type="file" name="filefield" id="filefield"/>
                        </label>
                        </td>
                      </tr>
                        <tr>
                        <td>&nbsp;</td>
                        <td><label>
                          <input name="thisID" type="hidden" value="<?php echo $targetID; ?>" />
                          <input type="submit" name="button" id="button" value="Make Changes" />
                        </label></td>
                        </tr>
                    </table>
                    </form>
             </div>
          </div>
           <br/>
            <br/>                  
            </div>           
            <div id="footer">   
                <div id=footerwrap>
                    <div id="foot1">
                      <ul class="a">
                        </ul>
                    </div>
                </div>              
            </div>                  
                <!--here is where some javascrip goes regarding the navigation main menu*-->
                <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
                <script src="js/general.js"></script>
        </body>
        </html>

Any help would be much appreciated. Thanks very much indeed in advance.

Check your permissions on the path /production_images/ . That seems like the most likely issue. The path is either not writable by your server user or the path doesn't exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM