0
function uploadFile() {
            global $attachments;
            while(list($key,$value) = each($_FILES[images][name]))
            {
            if(!empty($value))
            {
            $filename = $value;
            //the Array will be used later to attach the files and then remove them from server ! array_push($attachments, $filename);
            $dir = "/home/blah/Music/$filename";
            chmod("/home/blah/Music",0777);
            $success = copy($_FILES[images][tmp_name][$key], $dir);
            }
            //
            }
            //
            if ($success) {
            echo " Files Uploaded Successfully<BR>";
  //
  }else {
     exit("Sorry the server was unable to upload the files...");
        }
                                //
        }

尝试上传文件,然后使用 PHP Mailer 将其作为邮件附件发送

错误:

Warning: copy(/home/blah/Music/Aerial_view_of_Yamuna_Expressway.jpeg): failed to open stream: Permission denied in /opt/lampp/htdocs/UI/user/joinmeeting.php on line 292

更新 :

blah@my001server:~$  ls -la for /home/blah/Music
ls: cannot access for: No such file or directory
/home/blah/Music:
total 8
drwxr-xr-x  2 blah blah 4096 Jul  4 10:20 .
drwxr-xr-x 67 blah blah 4096 Sep 21 10:18 ..

为什么我的 linux 系统不允许复制文件?

4

3 回答 3

1

检查目标文件夹的权限。
设置777再试一次

$ chmod 777 folder

因此,正如我们现在看到的,您没有为 Music 文件夹设置写权限。
从控制台手动设置,而不是从 php 脚本。

于 2012-09-21T06:55:33.327 回答
0

尝试使用 move_uploaded_file (http://php.net/manual/en/function.move-uploaded-file.php) 而不是复制:

move_uploaded_file($_FILES[images][tmp_name][$key], $dir);
于 2012-09-21T06:58:38.550 回答
0

好的,您的编辑有点奇怪。

blah@my001server:~$  ls -la for /home/blah/Music
ls: cannot access for: No such file or directory
/home/blah/Music:
total 8
drwxr-xr-x  2 blah blah 4096 Jul  4 10:20 .
drwxr-xr-x 67 blah blah 4096 Sep 21 10:18 ..

该命令是错误的,因为它实际上是:

blah@my001server:~$  ls -la /home/blah/Music

你应该跑步。

但是好的,我看到了一个问题。.表示整个文件夹的文件没有权限www-data。这意味着您的 Linux 发行版的默认网络用户可能无法访问这些文件。

由于 PHP 在 webuser 下运行,www-dataLinux 不允许它cpvigedit(或其他任何东西)它不拥有任何东西。

你可以试试:

sudo chown /home/blah/Music www-data

反而。这应该给予一些权限来www-data控制目录中的文件。

当然,这会引发更大的问题。理想情况下,由于安全需要,您希望断开任何上传目录或任何与实际 Web 服务器的连接。

于 2012-09-21T12:17:08.287 回答