Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 8835720a authored by 65160117's avatar 65160117
Browse files

Edit server.js

parent 69aa9e9e
No related branches found
No related tags found
No related merge requests found
......@@ -18,22 +18,16 @@ app.use(express.static(path.join(__dirname, 'public')));
// กำหนดการจัดเก็บไฟล์
const storage = multer.diskStorage({
destination: function (req, file, cb) {
const uploadDir = path.join(__dirname, 'public/uploads');
const uploadDir = 'public/uploads';
// สร้างโฟลเดอร์ถ้ายังไม่มี
if (!fs.existsSync(uploadDir)){
try {
fs.mkdirSync(uploadDir, { recursive: true });
} catch (err) {
console.error('Error creating upload directory:', err);
return cb(err);
}
}
cb(null, uploadDir);
},
filename: function (req, file, cb) {
// สร้างชื่อไฟล์ใหม่เพื่อป้องกันการซ้ำ
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
cb(null, uniqueSuffix + path.extname(file.originalname));
cb(null, Date.now() + path.extname(file.originalname));
}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment