在父目录中移动文件

Move File in parent directory

我认为图像说明了一切,但可以解释我的问题,我通过 php 在服务器上上传了一些图像,它们被上传到 PHP 目录(我不知道为什么), 现在我想将它们移动到 "sister" 目录 Bilder 和它们的 "child" Beschreibung.

     $query ="SELECT id FROM hausaufgaben ORDER BY id ASC";
$res = mysqli_query($connect,$query);
$id = 0;

while($row = mysqli_fetch_array($res)){
$id = $row['id'];
}

$path = "Beschreibung_$id.png";

$actualpath = "http://mywebsite.com/Hausaufgabenplaner/Bilder/Beschreibung/$path";


$mydate=getdate(date("U"));
$Erstellungsdatum = "$mydate[weekday], $mydate[mday] $mydate[month], $mydate[year]";


$query = " Insert into hausaufgaben(beschreibung,Abgabedatum,Erstellungsdatum,Fach,DeviceID, Beschreibung_Image) values ('$beschreibung','$Abgabedatum', '$Erstellungsdatum','$Fach','$DeviceID','$image');";
         if(mysqli_query($connect,$query)){
        file_put_contents($path,base64_decode($image));
        rename("$path", "/Hausaufgabenplaner/Bilder/Beschreibung/$path");
        echo "Successfully Uploaded";
    }


    mysqli_query($connect, $query) or die (mysqli_error($connect));
    mysqli_close($connect);

I uploaded some images over php on the server and they are uploaded on the PHP directory (I don't know why)

根据您提供的代码,这是您上传图片的方式:

$path = "Beschreibung_$id.png";
file_put_contents($path,base64_decode($image));

没有指定目录,因此图像将被写入与当前 PHP 文件相同的目录 运行。

now I want to move them in the "sister" directory Bilder and their "child" Beschreibung.

同样,根据您提供的代码:

rename("$path", "/Hausaufgabenplaner/Bilder/Beschreibung/$path");

您只是指定了相对路径,而不是绝对路径。所以这将转换为:/Current Directory/Hausaufgabenplaner/Bilder/Beschreibung/$path

回显即可找到绝对路径$_SERVER['DOCUMENT_ROOT']