【发布时间】:2014-03-17 03:29:43
【问题描述】:
向正在阅读本文的人问好!
目前我有一个 php 页面,允许用户将文件上传到我的服务器的指定目录。这是我用来做的:
if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
chmod($uploadpath, 0777);
$uploadpath = $uploadpath . basename( $_FILES['fileup']['name']); // gets the file name
$sepext = explode('.', strtolower($_FILES['fileup']['name']));
$type = end($sepext); // gets extension
list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); // gets image width and height
$err = ''; // to store the errors
// If no errors, upload the image, else, output the errors
if($err == '') {
if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) {
chmod($uploadpath, 0777);
echo '<br/><br/>File successfully uploaded:' .$uploadpath.'</b>';
}
else echo '<b>Unable to upload the file.</b>';
}
else echo $err;
}
上传部分就像一个魅力,文件上传到服务器上但是一旦上传,我无法以另一个用户的身份删除文件。目前上传文件的用户是 Apache 用户“www-data”。
我确实认为问题与为我尝试使用的上传文件设置的权限有关:
chmod($uploadpath,0777);
但这无济于事.. 文件仍然无法删除。如果我是 root 使用“rm -rf /directorypath”,我可以通过 SSH 删除它,但如果我浏览它,则无法删除它。
有什么建议吗?非常感谢任何帮助!
【问题讨论】:
标签: php html linux apache debian