What are the potential pitfalls of using touch() to create a new file for uploaded images in PHP?

Using touch() to create a new file for uploaded images in PHP can be risky because it only creates an empty file and does not validate the file content. This can lead to security vulnerabilities if malicious files are uploaded. To mitigate this risk, it is recommended to use functions like move_uploaded_file() which not only moves the uploaded file to a specified location but also performs checks on the file to ensure its safety.

// Example of moving uploaded file to a specified location
$targetDir = "uploads/";
$targetFile = $targetDir . basename($_FILES["fileToUpload"]["name"]);

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $targetFile)) {
    echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
    echo "Sorry, there was an error uploading your file.";
}