What is the potential issue with uploading files to the same server as the script in terms of traffic and storage space?
Uploading files to the same server as the script can lead to increased traffic and storage space usage, potentially causing performance issues and consuming valuable resources. To solve this problem, it is recommended to store uploaded files in a separate directory or use a cloud storage service to offload the storage burden from the server.
// Set the upload directory outside of the script directory
$uploadDirectory = '/var/www/uploads/';
// Check if the directory exists, if not create it
if (!file_exists($uploadDirectory)) {
mkdir($uploadDirectory, 0777, true);
}
// Move uploaded file to the designated directory
move_uploaded_file($_FILES['file']['tmp_name'], $uploadDirectory . $_FILES['file']['name']);