Ich mache eine Website, die es einem Benutzer (dem Administrator und Besitzer der Website) erlaubt, seine eigenen Fotos in eine Galerie auf der Website hochzuladen. Das Foto wird hochgeladen und alles, aber wenn ich versuche, es in das Verzeichnis zu verschieben, erhalte ich einen Fehler. Ich habe viele Dinge ausprobiert, sogar alle Berechtigungen auf dem cpanel auf ecowebhosting.co.uk erlaubt. Aber mein Skript sollte dort trotzdem hochladen können ohne Gruppenberechtigungen. Hier ist mein PHP-Skript:PHP move_uploaded_file Server Fehler
$target_dir = "/assets/collages/";
$target_file = $target_dir.basename($_FILES['image']['name']);
$uploadOk = 1;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
$upload_dir = $_SERVER['DOCUMENT_ROOT'] . "assets/collages/";
if (is_dir($upload_dir)) {
// do upload logic here
} else {
echo 'Upload directory is not writable, or does not exist.';
}
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check !== false) {
$uploadOk = 1;
} else {
echo "File is not an image.<br>";
$uploadOk = 0;
}
if (file_exists($target_file)) {
echo "Sorry, file already exists.<br>";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.<br>";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["image"]["name"], $target_file)) {
echo "The file ". basename($_FILES["image"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.<br>";
}
}
}
Und hier ist meine Form (unter Verwendung von Bootstrap):
<form method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-md-2">
<div class="form-group">
<label for="year">Year</label>
<input type="text" name="year" id="year" placeholder="Year" class="form-control" />
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="title">Title</label>
<input type="text" name="title" id="title" placeholder="Title" class="form-control" />
</div>
</div>
</div>
<div class="form-group">
<label for="image">Image File</label>
<input name="image" type="file" id="image">
<p class="help-block">Chose the collage image you would like to add.</p>
</div>
<button type="submit" class="btn btn-success" name="submit">Submit</button>
</form>
Und schließlich, es auf einem Hosting-Paket ist, so dass ich weiß nicht, ob das würde ein Unterschied.
Und welchen Fehler bekommen Sie? Überprüfen Sie, ob Sie Zugriff auf Ihre Web-Server-Protokolle haben (möglicherweise aus dem Provider-Kontrollfeld). –
@MarcCompte xxxxxxxxx.com xx.xxx.xx.x - - [07/Jun/2016: 22: 41: 12 +0100] "GET http://xxxxxxxxx.com/ftpriurNj.cgi HTTP/1.1" 200 169 " - "" JustAnInstaller/0.1 "Das ist alles in meinen Logs. – Twonty2
Das ist ein Eintrag über einen GET-Aufruf an eine CGI-Datei. Es muss etwas über einen POST-Aufruf an Ihre PHP-Datei sein. –