1

I have a problem that I can't resolve for some time now.

I am making simple file upload with PHP and XMLHttpRequest. I am taking data from a form and sending it to the backend script.

Data is sent successfully and I can display it, but I can't move uploaded image to a folder because I get an error

Warning: move_uploaded_file(image_test/cart.png): failed to open stream: Permission denied in /srv/http/portfolio/admin/backend/write/blogs.php

At first, I thought it was permissions problem but these are permissions to root folder of the project

drwxr-xr-x 9 m1ck0 m1ck0 4096 13. nov. at 21:18 portfolio

Here are permissions of images folder that I am trying to upload the image to.

drwxr-xr-x 2 m1ck0 m1ck0 4096 13. nov. at 21:18 images

Here is PHP code

$sourcePath = $_FILES['image']['tmp_name'];
  $targetPath = "image_test/".$_FILES['image']['name'];

  echo $targetPath;
  if(!move_uploaded_file($sourcePath, $targetPath)) {
    echo 'error';
  } else {
    echo 'done';
  }

http folder is also owned by me.

Does anyone know what could I do?

I am using OS: Manjaro Linux x86_64

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Mileta Dulovic
  • 1,036
  • 1
  • 14
  • 33
  • Have you seen [this Q&A?](https://stackoverflow.com/q/8103860/1415724) – Funk Forty Niner Dec 02 '19 at 21:45
  • Another thing you can try is using the full system path, instead of a relative one. I.e.: `/srv/http/image_folder_XYZ/`. – Funk Forty Niner Dec 02 '19 at 21:45
  • Thanks for your time. I tried both of those. I am owner of the folder that I am trying to upload to so there is that. An absolute path is also giving the same error. – Mileta Dulovic Dec 02 '19 at 21:47
  • Welcome. Re-check all of your paths and for any given included file and/or folder. Btw, Linux is case-sensitive so make sure there isn't even the one file that isn't misspelled. This could be anything. I'll keep scratching my head, just hope I don't end up bald, cuz you'll owe me a wig! *hahaha!!* :D kidding ;-) – Funk Forty Niner Dec 02 '19 at 21:51
  • Well, I was thinking about file name and intentionally misspelled it. It said that the folder doesn't exist and to check the name of it. So it means that the folder does exist. I also triple double-checked it. I am nearly bald so yeah, we might both need one :D – Mileta Dulovic Dec 02 '19 at 21:53
  • Kind of a last ditch effort. Check the form you're using for this. It might be because that there isn't a proper enctype for it, and/or not using the correct method, or the input for it isn't named.... Lordie.. again..... this could be anything at all. It could also be something real silly, or the `.ini` files as to what the max upload settings are. I hope you find the bugger :-) – Funk Forty Niner Dec 02 '19 at 22:04
  • Okay. I think I am on something. I tried this ```echo get_current_user();``` and got ```m1ck0``` but after ```echo exec('whoami');``` I got ```http```. This is probably a problem. But when I execute ```whoami``` from console I get ```m1ck0```. ```http``` is only printed after command is ran firectly from PHP. Any ideas? – Mileta Dulovic Dec 02 '19 at 22:13
  • Sorry, I don't. Try posting in https://unix.stackexchange.com/ – Funk Forty Niner Dec 02 '19 at 22:34
  • 2
    I will. Also I will get back here if I fix this. – Mileta Dulovic Dec 02 '19 at 22:45

1 Answers1

0

You will need to give write permission to that folder, it currently doesn't appear to have that.

You could use chmod to do this.

Run_Script
  • 2,487
  • 2
  • 15
  • 30
  • I gave it ```775``` now it looks like this ```drwxrwxr-x 2 m1ck0 m1ck0 4096 13. nov. at 21:18 images``` and I still have the same error. – Mileta Dulovic Dec 02 '19 at 21:36