Ich habe ein Bild-Upload-Seite mit dem folgenden:PHP Upload mehrerer Bilder beim Einfügen mehrerer „Wählen Sie“ Daten in Mysql
Ein Mehrfach-Auswahl-Box, die aufgelistet 9 Kategorien. Ein Texteingabefeld für den Bild-Alt-Text. Ein Upload-Feld für mehrere Dateien.
Ziel ist es, mehrere Bilder gleichzeitig hochladen zu können, die Texteingabe für den Alt-Text zu speichern und jede der ausgewählten Kategorien zu speichern.
Das Skript, das ich geschrieben habe, ist nicht unbedingt fehlerhaft, da der Fehler, den ich erhalte, der in das Skript Sorry, there was a problem uploading your images.
eingebaute ist.
Die gesamte Seite ist hier:
<?php
include($_SERVER['DOCUMENT_ROOT'].'/settings/functions.php');
include($_SERVER['DOCUMENT_ROOT'].'/settings/config.php');
include($_SERVER['DOCUMENT_ROOT'].'/php/top-notification.php');
include($_SERVER['DOCUMENT_ROOT'].'/php/nav.php');
?>
<div class="container">
<?php
// Connect to database
$conn = getConnected("lucycypher");
// Don't execute upload script unless "upload" is clicked
if(isset($_POST['submit'])) {
// This is the directory where images will be saved
$target = $_SERVER['DOCUMENT_ROOT']."/gallery/";
// This gets all the other information from the form
$img_category = implode(',', $_POST['img_category']);
$img_name = $_POST['img_name'];
// Count the image files
if(count($_FILES['img_file']['tmp_name'])) {
// Loop through each file
foreach ($_FILES['img_file']['tmp_name'] as $img_file) {
// moves the image
if(move_uploaded_file($img_file, $target)) {
// if upload is a success query data into db
mysqli_query($conn, "INSERT INTO gallery_img (img_name, img_category, img_location) VALUES ('$img_name', '$img_category', '$img_file')") ;
echo '<div class="alert alert-success margin-top">Your imags were successfuly uploaded.</div>';
}
else {
echo '<div class="alert alert-danger margin-top">Sorry, there was a problem uploading your images.</div>';
}
}
}
}
?>
<form class="form-horizontal" method="POST" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<fieldset>
<!-- Form Name -->
<legend>Upload Image</legend>
<!-- Select Multiple -->
<div class="form-group">
<label class="col-md-4 control-label" for="img_category">Category</label>
<div class="col-md-4">
<select id="img_category" name="img_category[]" class="form-control" multiple="multiple">
<option value="horror">Horror</option>
<option value="occult">Occult</option>
<option value="goth">Goth</option>
<option value="industrial">Industrial</option>
<option value="fashion">Fashion</option>
<option value="fetish">Fetish</option>
<option value="avante-garde">Avante-Garde</option>
<option value="cosplay">Cosplay</option>
<option value="nude">Nude</option>
</select>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="img_name">Name:</label>
<div class="col-md-4">
<input id="img_name" name="img_name" type="text" placeholder="Image Name" class="form-control input-md" required="">
</div>
</div>
<!-- File Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="img_file">Image</label>
<div class="col-md-4">
<input id="img_file" name="img_file[]" class="input-file" type="file" multiple>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="submit">Ready?</label>
<div class="col-md-4">
<button type="submit" name="submit" class="btn btn-primary">Upload</button>
</div>
</div>
</fieldset>
</form>
</div>
<?php include($_SERVER['DOCUMENT_ROOT'].'/php/footer.php'); ?>
Und mein Datenbank-Layout ist:
ID mediumint(10) AUTO_INCREMENT
img_name varchar(50)
img_category varchar(200)
img_location blob
img_time timestamp on update CURRENT_TIMESTAMP
Wenn ich mehrere Kategorien auswählen, um eine Bilddatei auszuwählen, und geben Sie den Text in dem nichts Textfeld bekommt zur Datenbank hinzugefügt und das Bild wird nicht auf den Server hochgeladen.
Ich bekomme einfach nur die Sorry, there was a problem uploading your images.
Fehler.
Mein gallery
Verzeichnis hat 775
Berechtigungen.
Ihr Ziel ist ein directrory sein. '$ Target = $ _SERVER [ 'DOCUMENT_ROOT'] "/ gallery /";' die kann korrekt sein, aber Sie fügen die Datei hinzu, die Sie auf Ihr Ziel hochladen möchten, so dass Sie kein Zielverzeichnis mehr haben. Sie müssen diese Zeile also löschen. '$ Ziel = $ Ziel. Basisname ($ _ FILES ['img_file'] ['tmp_name']); ' – Franco
Gelöscht. Hochladen des Uploads Gleiche Ergebnisse. –
Warum ist der Datentyp der 'img_location' Spalte' blob'? Sie laden trotzdem Dateien auf den Server hoch? –