Ik heb script waarmee je foto's kan uploaden naar de map images, dit werkt. Maar in de database wil ik in de kolom: image een pad hebben images/NaamVanAfbeelding.jpg.
Op dit moment krijg ik het pad images/\
Ik snap niet waar de \ vandaan komt, maar daar zal de naam van de foto moeten komen.
De naam en beschrijving worden wel in de db gezet.
Mijn vraag is: hoe krijg ik in de database in de kolom image het pad: images/NaamAfbeelding.jpg?
alvast bedankt:
index.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once('connect.php');
require_once('class_foto_video.php');
$database = new Database();
if(isset($_FILES['file'])){
$fileupload = new FotoVideo($database);
$fileupload->UploadFoto();
if($fileupload -> uploadfile()){
echo 'Bestand is geüpload';
}
}
if (isset($_POST["submit"])) {
$naam = $_POST['name'];
//$filepath = $_POST['file'];
$beschrijving = $_POST['description'];
$fileupload = new FotoVideo($database);
$fileupload -> VoegFotoInDatabase($naam,$beschrijving);
echo 'data toegevoegd';
}
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Foto toevoegen</title>
</head>
<body>
<h2>Foto uploaden</h2>
<form align="center" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
Naam: <input type="text" name="name" /><br />
Select upload file: <input type="file" name="file" required="yes" /><br />
<textarea rows="4" cols="50" name="description"> </textarea><br />
<input type="submit" name="submit" value="Verstuur" />
</form>
<a href="dashboard.php">klik hier om terug te gaan</a>
</body>
</html>
class:
class FotoVideo{
private $database;
private $src = "images/";
private $tmp;
private $filename;
private $type;
private $uploadfile;
public function UploadFoto(){
$this -> filename = $_FILES["file"]["name"];
$this -> tmp = $_FILES["file"]["tmp_name"];
$this -> uploadfile = $this -> src . basename($this -> filename);
}
public function uploadfile(){
if(move_uploaded_file($this -> tmp, $this -> uploadfile)){
return true;
}
}
public function VoegFotoInDatabase($naam,$beschrijving){
$filepath = $this->src . DIRECTORY_SEPARATOR . $this->filename;
$stmt = $this->database->prepare("INSERT INTO foto(naam,image,beschrijving) VALUES (?, ?, ?)");
$stmt->bind_param('sss', $naam,$filepath ,$beschrijving );
$naam = $_POST['name'];
//$filepath = $_POST['file'];
$beschrijving = $_POST['description'];
$stmt->execute();
$stmt->close();
}
}