在 apache 服务器中创建一个文件

在 apache 服务器中创建一个文件

我正在尝试在我的 apache2 服务器上创建一个非常基本的文件传输网页,并且成功了,然后我将 index.php 文件移动到一个文件夹中,以便整理我的其他项目。我记得当我的网站运行时,我授予它创建和保存文件的权限:

sudo chown www-data cloud_data/ (cloud_data 是文件保存的地方)

但是在我将 index.php 及其所有依赖文件和文件夹(如 cloud_data 和 upload.php)移动到新文件夹后,我无法使用该站点创建文件,我甚至尝试再次授予文件和文件夹权限,但没有成功。

上传文件

<?php
header ('location:index.php');
$destination_path = getenv("DOCUMENT_ROOT")."/cloud_data/"; 
$target_path = $destination_path;
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$file_n = $_POST['uploadedfile'];
echo "Source=" .        $_FILES['uploadedfile']['name'] . "<br>"; 
echo "Destination=" .   $destination_path . "<br>"; 
echo "Target path=" .   $target_path . "<br>"; 
echo "Size=" .          $_FILES['uploadedfile']['size'] . "<br />"; 
//echo "Tmp name=" .    $_FILES['uploadedfile']['tmp_name'] . "<br />"; 


if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name'])." has been uploaded";
    $path_info = pathinfo($target_path)['extension'];
    echo "File extention: ".$path_info;
} else{
    echo "There was an error uploading the file, please try again!";
}

?>

索引.php

<html>
<head>
    <title>1NV1C7U5 Cloud Server</title>
    <link rel="icon" type="image/jpg" href="/photos/AP_B.jpeg">
</head>
<body style="background-image: url('photos/back.jpg');background-repeat: no-repeat;  background-attachment: fixed;background-size: cover;">
    <center>
    <style>
    .upload-btn-wrapper {
      position: relative;
      overflow: hidden;
      display: inline-block;
    }

    .btn {

      border: 4px solid black;
      color: gray;
      background-color: white;
      padding: 8px 20px;
      border-radius: 50px;
      font-size: 20px;
      font-weight: bold;
    }

    .upload-btn-wrapper input[type=file] {
      font-size: 100px;
      position: absolute;
      left: 0;
      top: 0;
      opacity: 0;
    }
    </style>
    <style>
    .zoom {
      transition: transform 0.1s;
      margin: 0 auto;
    }

    .zoom:hover {
      transform: scale(1.2  );
    }
    </style>

    <header>
        <p style="text-align:center"><img src="/photos/cloud_cool.png" ;align="center" alt="Welcome To AgentPluton.com" width="1000"/></p>
        <p style="border: solid 4px darkblue;border-radius:10px"><h1  style="color:cyan; font-family:courire;display:inline; border: solid 6px lime;border-radius:10px"> 1NV1C7U5</h1><h1 style="color:white; font-family:cursive;display:inline; border: solid 6px lime;border-radius:10px"> Cloud Server </h1></p>
    </header>
    <form enctype="multipart/form-data" action="upload.php" method="post">
                <h1 style="color:lightblue; font-family:cursive; border: solid 3px cyan;border-radius:25px"> Select File: </h1>
           <p>
        <h2 style="color: whitesmoke;">
        <div class = "zoom">
        <div class="upload-btn-wrapper">
        <button class="btn", style="color: white; background-image: linear-gradient(to right,cyan,blue,cyan)">Select a file</button>
        <input type="file" name="uploadedfile" style="">
            </div></div>
        <br>
                <br>
        <br>
                <div class = "zoom">
        <input type="submit" name="Upload" value= "+"  style="width:125px; height:125px; background-image: linear-gradient(to right,cyan,blue,cyan); color: white; border-radius: 75px; border:4px solid #000000;font-size : 100px;"/>
                <br>Add
        </h2></div>
            </p>
        </form>
        <?php
        $del_f = $_POST["flnam"];
        unlink($del_f);
    ?>
        <?php
        $i = -1;
        echo "<table style='border-spacing: 50px;'><tr>";
        $fileList = glob('cloud_data/*');
            foreach($fileList as $filename)
        {
        $ext = pathinfo($filename)['extension'];
        $i=$i+1;
        if($i==3)
        {
            $i=0;
            echo"</tr>";
            echo"<tr>";
        }
        $pic = array("jpg","png","bmp","jpeg");
        $vid = array("mp4","webm","mkv","flv","vob","avi","m4v","mpeg");
        $aud = array("mp3","aac","aax","m4a","wav","vox","voc","wma");
        $com = array("zip","tar","gz","iso","xz");
        $adr = array("apk");
        $doc = array("pdf","doc","docx","csv","ods","txt");
        $cod = array("py","c","cpp","js","htm","html","php","jar","sh","qb","java");
        echo '<td><form action="index.php" method="post"><br><br><br><button class = "zoom" name="flnam", value="'.$filename.'", style="width: 125px;height:50px;border-radius: 50px;border: 2px solid darkblue;font-size:25px; background-image: linear-gradient(to right, white,cyan,blue) ;">DELETE</button><br><a href="'.$filename.'" style="color:white;" >';

        if(in_array($ext,$pic))
        {
            echo '<img class = "zoom" src="'.$filename.'";';
            }
        elseif(in_array($ext,$vid))
        {
            echo '<video class = "zoom" src="'.$filename.'";';
            }
        elseif(in_array($ext,$aud))
        {
            echo '<img class = "zoom" src="photos/aud.png";';
        }
        elseif(in_array($ext,$com))
        {
            echo '<img class = "zoom" src="photos/comp.png";';
        }
        elseif(in_array($ext,$adr))
        {
            echo '<img class = "zoom" src="photos/android.png";';
        }
        elseif(in_array($ext,$doc))
        {
            echo '<img class = "zoom" src="photos/doc.png";';
        }
        elseif(in_array($ext,$cod))
        {
            echo '<img class = "zoom" src="photos/cod.png";';
        }
        else
        {
                echo '<img class = "zoom" src="photos/unk.jpg";';
        }

        echo 'align="center" alt="'.$filename.'" width="312" height="312" style=" border-radius: 50px;border: 4px solid cyan;" /></a></form>';
        echo '<h3 style="color:white;text-overflow: ellipsis; width:350px; white-space: nowrap; overflow: hidden;">'.basename($filename),'</h3></td>';
        }
    echo"</table>";
        ?>
        </h1>
    </center>
    <footer style="color:white">made by "Agent Pluton"<br>email id: [email protected]</footer>
</body>
</html>

网页如下所示

请尽快提供帮助,因为我经常使用此页面

答案1

听起来仍然是权限问题,

尝试

sudo chown www-data:www-data -R /your/app/root/
sudo chmod 755 -R /your/app/root/

如果你有更多关于错误的信息,比如 php 日志输出,那就太好了

相关内容