简体   繁体   English

php文件上传所有权问题

[英]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). 我正在尝试在PHP中实现照片上传和调整大小(我正在使用LAMP堆栈和Imagick扩展来调整大小)。 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. 但是,每次我尝试上传文件时,默认情况下该文件的所有权都设置为www-data,这使得无法对文件进行任何更改。 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. 上传文件的用户将是运行PHP的用户。 Since you are uploading and manipulating the file from the same php instance, you should have full file rights. 由于您是从同一php实例上载和操作文件,因此您应该具有完整的文件权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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