PHP文件上传问题/文件权限

时间:2015-07-17 12:10:15

标签: php

在本地XAMPP服务器上存在文件上载(和/或)文件权限的一些脚本问题 - 报告文件上载错误。同样,用户文件夹是在成功注册此脚本后创建的(注意,这只是注册脚本,用户在注册后未登录):

if(mysql_query("INSERT INTO users(username,email,password) VALUES('$uname','$email','$upass')")) {

 ?>
     <script>alert('Successfully registered');</script>
 <?php

$_SERVER['QUERY_STRING'];
$foldername = $_POST['uname'];
$path = "users/";
$complete = $path.$foldername;

if (mkdir($complete, 0777)) {
  ?>
     <script>alert('Folder <?php echo "\"$foldername\""; ?> has been created';</script>
  <?php
}
  else {
   ?>
     <script>alert(Folder not created);</script>
   <?php
}               
}

当用户登录时,这大致是文件上传脚本的一部分:

    session_start();

$userfolder = $_SERVER["DOCUMENT_ROOT"]."/users/".$_SESSION['user'];
$filename = $_FILES['filep']['name'];
$filedir = $userfolder.'/'.$filename;

echo "$filedir".'<br />'.'<br />';

//echo getcwd();

    if ($_POST['action'] == "Load") {

        if (file_exists($filedir)) {
            ?>
                <script>alert('File" <?php echo $_FILES['filep']['name'] . "already exists."; ?>');</script>
            <?php
        }
            elseif (!is_writable($filedir)) {
                die ("Not writable !");
            }
                elseif (move_uploaded_file($_FILES['filep']['tmp_name'], $filedir)) {
                                ?>
                                    <script>alert('File "<?php echo "$filename"; ?> "loaded');</script> 
}  

我使用本地XAMPP安装C:/ xampp / ...并回显$ filedir报告C:/ xampp / htdocs / users / testuser /,所以文件路径应该没问题,但是我仍然得到错误'is_writable'和'move_uploaded_file functions'。也许值得一提的是文件路径中的$ _SESSION ['user']填充在另一个文件脚本中:

        if (isset($_POST['btn-login'])) {
        $email = mysql_real_escape_string($_POST['email']);
        $upass = mysql_real_escape_string($_POST['pass']);
        $sql = mysql_query("SELECT * FROM users WHERE email='".$email."'");
        $num = mysql_fetch_assoc($sql);

            if ($num['password'] == $upass) {
                $_SESSION['user'] = $num['username'];
                header ("Location: home.php");
            }

任何提示?谢谢

0 个答案:

没有答案