Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload files to the folder outside root folder in Linux server?

In my project, I have to upload some video files to a folder which lies outside the root folder. I am using simple php function move_uploaded_file to upload the file. I have tried with the code below.

$source  = $_FILES['Filedata']['tmp_name'];
$targetFile = '/usr/local/WowzaMediaServer-3.1.1/content/video.mp4'
move_uploaded_file($source,$targetFile);

But it is not working. Can we done it through move_uploaded_file. if not, suggest a better option to do this.

I have seen some similar question but nothing helps. So any help would be appreciated..

like image 500
Bibin Velayudhan Avatar asked May 06 '26 22:05

Bibin Velayudhan


2 Answers

Are you sure you're not in a chroot jail?

If so, your "absolute" path name could be pointing to the wrong place-- somewhere that doesn't exist.

If so, change the path to point to somewhere within the jail.

It may be necessary to mount --bind the directory you want this to go in into some location within the jail. (Note that a symbolic link will not work for getting out of jail.)

like image 97
zebediah49 Avatar answered May 08 '26 11:05

zebediah49


More than likely this is a simple permissions issue and quite easy to solve.

  1. Find the user that apache uses. To do this open up your httpd.conf file and look for something like:

    User apache
    Group apache

  2. Change the ownership of the folder that you're trying to upload to.

    chown -R apache.apache /usr/local/WowzaMediaServer-3.1.1/content/

  3. Change the permissions of the folder

    chmod -R 775 /usr/local/WowzaMediaServer-3.1.1/content/

And that should be that.

like image 30
Rob Forrest Avatar answered May 08 '26 11:05

Rob Forrest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!