简体   繁体   中英

php file uploads ownership issue

I'm trying to implement photo uploading and resizing in PHP (I'm using the LAMP stack and the Imagick extension for resizing). However, every time I try to upload a file, the file has the ownership set to www-data by default, which makes it impossible to apply any changes to the file. The following is the code i'm using:

<?php

if (is_uploaded_file($_FILES['picture']['tmp_name'])){

  $photoPath = $_SERVER['DOCUMENT_ROOT'] . '/photo_app/uploads/' . $_FILES['picture']['name'];

  if (move_uploaded_file($_FILES['picture']['tmp_name'], $photoPath)){

        $image = new Imagick($photoPath);
        $image -> scaleImage(250, 250, true);
        $image -> writeImage($photoPath);

  }   

}

?>

The photo gets moved in the right place, but no resizing occurs because of the ownership issue. Is there a way to resolve this? Thanks :)

The user of an uploaded file will be the user that PHP is running under. Since you are uploading and manipulating the file from the same php instance, you should have full file rights.

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