1

this is error getting from upload images, the images cant move and permission denied, I have also configured the directory but still same. anyone has an idea please help

Warning: move_uploaded_file(img/t-shirts-1.jpg): failed to open stream: Warning:Permission denied in /var/www/html/wp_inventori/edit.php on line 25 move_uploaded_file(): Unable to move '/tmp/phpUIcxe5' to 'img/t-shirts-1.jpg' in /var/www/html/wp_inventori/edit.php on line 25

if(isset($_FILES['imagen']['name']) && ($_FILES['imagen']['name']!="")){
    $target_dir = "img/";
    $file = $_FILES['imagen']['name'];
    $path = pathinfo($file);
    $filename = $path['filename'];
    $ext = $path['extension'];
    $temp_name = $_FILES['imagen']['tmp_name'];
    $path_filename_ext = $target_dir.$filename.".".$ext;
if (file_exists($path_filename_ext)) {
        echo "Sorry, file already exists.";
    }else{
       move_uploaded_file($temp_name,$path_filename_ext);
       echo "Congratulations! File Uploaded Successfully.";
   }
Nafeez Quraishi
  • 5,380
  • 2
  • 27
  • 34
atoy amsal
  • 11
  • 3
  • 1
    Are you sure this directory exists and if it does the user running the your application or the user running your web server has the correct rights to move this file to this location? – tmkiernan Aug 22 '19 at 15:15
  • Try using fullpath for $target_dir – Manzolo Aug 22 '19 at 15:17
  • Dear all I been changing permission and changing the user but the result still same, I have following all answer, currently, I using root and changed to apache also same doesn't solve out. any idea?? – atoy amsal Aug 23 '19 at 01:58
  • i have solved with this : sudo chcon -t httpd_sys_rw_content_t /var/www/html/images -R – atoy amsal Aug 30 '19 at 15:29

0 Answers0