Php 我正在尝试进行文件上传,但它不工作

Php 我正在尝试进行文件上传,但它不工作,php,ubuntu,file-upload,xampp,lampp,Php,Ubuntu,File Upload,Xampp,Lampp,我正在尝试为我的webchat应用程序轻松上传图像。我已经从Windows切换到Linux(xampp到lampp),现在我的文件上传脚本不再工作了。。。我试图用chown更改目录所有者,还试图更改读/写权限,但没有任何效果,所以现在我在stackoverflow上竭尽全力 我的上传文件夹在这里:/storage/www/messenger/data/profilepictures 我的脚本在这里:/storage/www/messenger/functions/upload-img.php 这

我正在尝试为我的webchat应用程序轻松上传图像。我已经从Windows切换到Linux(xampp到lampp),现在我的文件上传脚本不再工作了。。。我试图用chown更改目录所有者,还试图更改读/写权限,但没有任何效果,所以现在我在stackoverflow上竭尽全力

我的上传文件夹在这里:/storage/www/messenger/data/profilepictures

我的脚本在这里:/storage/www/messenger/functions/upload-img.php

这是我的密码

更改image.html

<form action="/messenger/functions/upload2" method="post" enctype="multipart/form-data">
<input type="file" name="datei"><br>
<input type="submit" value="Hochladen">
</form>


上传img.php

<?php
$upload_folder = '/messenger/data/profilepictures/'; //Upload directory

$filename = pathinfo($_FILES['datei']['name'], PATHINFO_FILENAME);

$extension = strtolower(pathinfo($_FILES['datei']['name'], PATHINFO_EXTENSION));


//checking of the file extention

$allowed_extensions = array('png', 'jpg', 'jpeg', 'gif');

if(!in_array($extension, $allowed_extensions)) {

 die("Only png, jpg, jpeg and gif-files are allowed");

}

//checking the file size

$max_size = 52428800; //500 MB

if($_FILES['datei']['size'] > $max_size) {

 die("500MB is the max file size");

}

//checking if the file is ok

if(function_exists('exif_imagetype')) { //Die exif_imagetype-Funktion erfordert die exif-Erweiterung auf dem Server

 $allowed_types = array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF);

 $detected_type = exif_imagetype($_FILES['datei']['tmp_name']);

 if(!in_array($detected_type, $allowed_types)) {

 die("you are not allowed to upload other files than pictures");

 }

}

//path to upload

$new_path = $upload_folder.$filename.'.'.$extension;

//Neuer Dateiname falls die Datei bereits existiert

if(file_exists($new_path)) { //Falls Datei existiert, hänge eine Zahl an den Dateinamen

 $id = 1;



do {



$new_path = $upload_folder.$filename.'_'.$id.'.'.$extension;

 $id++;

 } while(file_exists($new_path));

}

//everything alright, move file to new pos.

move_uploaded_file($_FILES['datei']['tmp_name'], $new_path);

echo 'Bild erfolgreich hochgeladen: <a href="'.$new_path.'">'.$new_path.'</a>';

?>


提前感谢。

尝试使用
$\u服务器['DOCUMENT\u ROOT']
superglobal

之前:

$upload_folder='/messenger/data/profilepictures/

之后:

$upload\u folder=$\u SERVER['DOCUMENT\u ROOT']./messenger/data/profilepictures/