Ich versuche, ein Bild hochzuladen. Der Zweck ist, ein Bild auf dem Benutzerprofil hinzuzufügen. Um zu erreichen, dass ich ein einfaches Beispiel mache, wo ich ein Bild von meinem Computer aktualisiere, einige Überprüfungen mache und ob das Bild in Ordnung ist, dann aktualisiere ich es auf den Ordner "Fotos" (im cpanel, public_html/Account/Fotos). Das Problem ist, dass alles gut aussieht, aber wenn ich dann auf diesen Pfad im cPanel gehe, ist das Bild nicht da. Schreibe ich den Pfad falsch? HierLaden Sie ein Bild mit PHP und HTML zum cPanel
ist der vollständige Code:
HTML
<html>
<body>
<form action="/My-code/upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
upload.php
<?php
$target_dir = "Account/photos/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
echo $target_file;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else {
echo "wally1 " . $_FILES["fileToUpload"]["tmp_name"];
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $_FILES["fileToUpload"]["name"])) {
echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
Irgendwelche Ideen, was im falsch? Und auch, ist es möglich zu tun, was ich versuche, richtig zu machen?
Vielen Dank im Voraus
Move Upload-Datei funktioniert nicht – devpro
Danke, ich habe es geändert, aber immer noch nicht im cPanel hochladen .. – AlguienEnEsteMundo
Ordnername ist das gleiche wie "Konto" mit Kapital A? – devpro