sql >> Database >  >> RDS >> Mysql

Upload afbeelding naar server en sla afbeeldingspad op in mysql-database

SQL:

CREATE TABLE `uploads` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(255) NOT NULL,
  `path` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

PHP:

$file_path = "uploads/";

$file_path = $file_path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path)) {
  // replace $host,$username,$password,$dbname with real info
  $link=mysqli_connect($host,$username,$password,$dbname);
  mysqli_query($link,"INSERT INTO `files` (filename,path) VALUES ('".$_FILES['uploaded_file']['tmp_name']."','".$file_path."')") or trigger_error($link->error."[ $sql]");
  mysqli_close($link);

} else{
    echo "fail";


  1. Gelijktijdige MySQL-updates

  2. Verbinding met MySQL-server verbroken bij verbinding met externe MySQL-server

  3. Dynamische draaitabel maken met de functie QUOTENAME

  4. Hoe mySQL-database te verbinden met C++