If you’re looking for an example: symfony2 file upload with related entities The PHP way: SQL
|
1 2 3 4 5 6 7 |
CREATE TABLE `file` ( `id` int(10) unsigned NOT NULL, `full_path` varchar(255) NOT NULL, `filename` varchar(255) NOT NULL, PRIMARY KEY (`id`), KEY `filename` (`filename`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
HTML
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<!doctype html> <html> <body> <form method="post" enctype="multipart/form-data"> <input type="file" name="file[]" multiple> <button type="submit">Upload</button> </form> </body> </html> <?php $mysql = new mysqli('localhost','username','password','dbname'); $upload_dir = 'uploads'; $i = 0; foreach ($_FILES as $file) { if(is_uploaded_file($file['tmp_name']{$i})) { $destination = __DIR__ . DIRECTORY_SEPARATOR . $upload_dir . DIRECTORY_SEPARATOR . $file['name']{$i}; move_uploaded_file($file['tmp_name']{$i}, $destination); $mysql->query("INSERT INTO file (id, full_path, filename) VALUES (NULL,'" . $destination. "','" . $file['name']{$i} ."')"); } $i++; } ?> |
15 minutes later. Success. The symfony2 way: How to handle File Uploads with Doctrine Multiple File Uploads with Symfony2 Syntax Error. Head Explodes. 3 days later, time wasted. And this is why Symfony2 sucks. Can you […]