screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; function App() { const [selectedFile, setSelectedFile] = useState(null); const handleFileChange = (event) => { const file = event.target.files[0]; setSelectedFile(file); }; const uploadFile = () => { if (selectedFile) { const timestamp = Date.now(); const fileName = `${timestamp}_${selectedFile.name}`; // Here, you can perform your file upload logic, for example using a server-side API or a third-party library. // Replace the following line with your actual upload logic. console.log('Uploading file with the new filename:', fileName); alert('added timestamp to filename') } else { alert('Please select a file first.'); } }; return ( <div className='container'> <h3>React Js Add Timestamp To Filename Before Image Upload</h3> <input type="file" onChange={handleFileChange} /> <button onClick={uploadFile}>Upload</button> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { max-width: 500px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); display: flex; flex-direction: column; align-items: center; justify-content: center; } /* Styles for the upload button */ .container button { margin-top: 10px; padding: 10px 20px; background-color: #007BFF; color: white; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s ease; } .container button:hover { background-color: #0056b3; } </style> </body> </html>