0

I just started a little project on a raspberry pi running Raspberry Pi OS. I have a vanilla apache2 installation where a php script moves a send file (via http POST) to an usb stick. The usb stick is mounted via usbmount and uses for the mounting process a specific user and group which are also used by the webserver. The php script looks like this:
$fname = '/media/usb/' . date('dmYHisv') . $_FILES['userfile']['name']; move_uploaded_file($_FILES['userfile']['tmp_name'],$fname);

This works just fine.... UNTIL I am using "sudo pcmanfm" to view the files on the usbstick in /media/usb.

After executing said command I cannot save any file to the drive. No matter what I try the webserver is not capable of moving the file. It took me way too long to realise this and I am deeply interested if someone can help me out and tell my why this happens.

  • Please share more details. You haven't shared any code that contains this `sudo` call, or are you running it on the terminal? – Nico Haase Jun 28 '21 at 10:09
  • My bad, yes I am running "sudo pcmanfm" in the standard Raspberrian OS terminal to open a new instance of pcmanfm with root rights. – Martin Kleinschrot Jun 28 '21 at 10:10
  • Then this is not related to PHP or Apache, I would assume? After all, if you are using the terminal to run `sudo pcmanfm`, how is this related to programming after all? – Nico Haase Jun 28 '21 at 10:13
  • 1
    `No matter what I try the webserver is not capable of moving the file` ...so do you get an error or warning from the PHP? Have you switched on errors and warnings so you could see them? It might give you a clue. But maybe the drive is simply locked by this other application, so nothing else can write to it. If so, move_uploaded_file should give you a warning about permissions (or similar). – ADyson Jun 28 '21 at 10:13
  • I tried getting errors displayed with display_errors in the php.ini as well as adding some error collecting code to my .php script. None showed any errrors unfortunately. I am also thinking that somehow the drive must be locked but I am confused why it would lock. After closing the "locking" process (the root filemanager) the drive is still not writeable by the webserver. Only a reboot fixes this problem. – Martin Kleinschrot Jun 28 '21 at 10:38
  • Can anything else write to it after you close the file manager? Maybe the application somehow changes the filesystem permissions... have you compared them before and after? as it's a temporary drive it's possible a reboot could reset them I guess. – ADyson Jun 28 '21 at 10:52
  • 1
    If there are no errors shown, how did you check that the error occurs? – Nico Haase Jun 28 '21 at 11:35

0 Answers0