我正在创建一个在file_share.php中请求用户名的文件上传表单,然后应该转到允许用户上传文件的上传表单upload.php。
问题在于这句话:
`$full_path = sprintf("/home/dfatoki11/uploading/%s/%s", $username, $filename);`当我运行该文件时,它说写入会话数据失败,错误被拒绝权限。当设置临时文件来存储上传的文件时,我应该使用哪个目录,以及如何在aws/apache服务器上设置权限?
fileshare.php
<?php
session_start();
$username = $_SESSION['username'];
echo $_SESSION['username'];
?>
<?php
$myFiles = sprintf("/home/dfatoki11/uploading/%s/%s", $userName, $filename);
$files=scandir($myFiles);
$full_path = sprintf("/home/dfatoki11/uploading/%s/%s", $username, $filename);
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mime = $finfo->file($full_path);
header("content-Type:" .$mime);
readfile($full_path);
?>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<p>
<label for="file">Choose a file to upload:</label>
<input name="uploadedfile" type="file" id="file" />
<input type="submit" value="Upload File" />
</p>
</form>upload.php
<?php
session_start();
// Get the filename and make sure it is valid
$filename = basename($_FILES['uploadedfile']['name']);
if( !preg_match('/^[\w_\.\-]+$/', $filename) ){
echo "Invalid filename";
exit();
}
// Get the username and make sure it is valid
$username = $_SESSION['username'];
if( !preg_match('/^[\w_\-]+$/', $username) ){
echo "Invalid username";
exit();
}
$full_path = sprintf("/home/dfatoki11/uploading/%s/%s", $username, $filename);
if( move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $full_path) ){
header("Location: file_share.php");
exit();
}else{
header("Location: login.php");
exit();
}
?>发布于 2014-09-16 10:38:08
您可能必须为您的/home文件夹授予用户"www-data“权限。如何做到这一点可以在这里找到:How to give apache permission to write to home directory?
https://stackoverflow.com/questions/25865843
复制相似问题