What are some best practices for file naming and storage paths in PHP file uploads?

When uploading files in PHP, it is important to follow best practices for file naming and storage paths to ensure security and organization. To prevent conflicts and potential security vulnerabilities, it is recommended to generate a unique filename for each uploaded file and store them in a secure directory outside of the web root.

// Generate a unique filename for uploaded files
$filename = uniqid() . '_' . $_FILES['file']['name'];

// Define the storage path outside of the web root
$storagePath = '/path/to/storage/';

// Move the uploaded file to the storage directory
move_uploaded_file($_FILES['file']['tmp_name'], $storagePath . $filename);