jemand anders
Erfahrenes Mitglied
Hallo,
ich habe hier eine File-Upload-Routine, die bis auf zwei Ausnahmen das tut, was ich will. Es geht nur um lokal auf meinen Rechner vorhandene Files.
Gruß
ich habe hier eine File-Upload-Routine, die bis auf zwei Ausnahmen das tut, was ich will. Es geht nur um lokal auf meinen Rechner vorhandene Files.
- ich brauche unbedingt den Pfad, von dem die Files geholt werden; momentan werden nur temporäre Pfade angezeigt, z. B. "/tmp/phpz4XvIB"
- die Files werden nicht im angegebenen Verzeichnis "upload/" gespeichert, obwohl das Verzeichnis existiert; sie werden gar nicht gespeichert (kopiert).
Gruß
Code:
<!doctype html>
<html>
<head>
<?php
include("config.php");
if(isset($_POST['submit'])){
for($i=0; $i < count($_FILES['upload']['name']); $i++) {
$name = $_FILES['upload']['name'][$i];
$target_dir = "upload/";
$target_file = $target_dir . basename($_FILES["upload"]["name"][$i]);
// Select file type
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Valid file extensions
$extensions_arr = array("jpg","jpeg","png","gif");
// Check extension
if( in_array($imageFileType,$extensions_arr) ){
// Insert record
$query = "insert into images (name, image) values('".$name."', ' ')";
mysqli_query($con,$query) or die(mysqli_error($con));
// Upload file
move_uploaded_file($_FILES['upload']['tmp_name'][$i],$target_dir.$name);
}
}
}
?>
<form action="" enctype="multipart/form-data" method="post">
<input id='upload' name="upload[]" type="file" multiple="multiple" />
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Code:
create database temp;
use temp;
CREATE TABLE `images` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
`image` longtext NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Code:
<?php
$host = "localhost"; /* Host name */
$user = "temp"; /* User */
$password = "temp"; /* Password */
$dbname = "temp"; /* Database name */
// Create connection
$con = mysqli_connect($host, $user, $password, $dbname);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
?>
Zuletzt bearbeitet: