PHP upload permission problem

后端 未结 3 1293
你的背包
你的背包 2021-01-19 19:06

right guys ive ran into a problem with file permissions with the following upload form. a text file is passed to the upload/ dir by global users.

mysite$ ls          


        
相关标签:
3条回答
  • 2021-01-19 19:18

    move_uploaded_file uses umask(600). Use copy($source, $dest) instead of move.

    0 讨论(0)
  • 2021-01-19 19:27

    You can use chmod to change the file permissions.

    To get the permissions of a file, use fileperms.

    0 讨论(0)
  • 2021-01-19 19:30

    The user, that initially writes the files into your "/upload" directory, is the one that started the Apache instance running a PHP module.

    In other words, PHP is the "owner" of all uploaded files and through a PHP script you can change the permissions of all relevant uploaded files without providing any credentials at all:

    PHP chmod function

    A quick and dirty hack to make uploaded files writable to all users would be

    else 
          {
          move_uploaded_file($_FILES["file"]["tmp_name"], 
          $f="/home/user/mysite/upload/" . $_FILES["file"]["name"]); 
          chmod($f, 0777);
          echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; 
          }
    
    0 讨论(0)
提交回复
热议问题