0

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 :)

3
  • I doubt it is an ownership issue since the user www-data that is trying to manipulate the image is the one that uploaded it to begin with.
    – sberry
    Jul 19, 2012 at 1:07
  • Are you actually getting an error that indicates the web server doesn't have access to the file? Jul 19, 2012 at 1:30
  • I'm not actually getting any access errors. I'm just assuming that was it because the file has a different owner and for www-data though, the access rights are set to Read and Write Jul 19, 2012 at 1:39

1 Answer 1

1

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.

2
  • I don't think that I have the full rights to the uploaded file. When I right click on the uploaded file, it says www-data as the owner in the permissions tab and the access rights are set to read and write for www-data. The group is also www-data and access rights are set to Read only. At the bottom it says 'You are not the owner, so you cannot change these permissions'. Jul 19, 2012 at 1:32
  • 1
    PHP is often configured to run under its own user. That would, of course, be different from the user you are using to click on the file. Still, since PHP is creating the file, it has permissions to modify it.
    – MrGlass
    Jul 19, 2012 at 2:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.