How can PHP scripts handle file permissions when uploading files?
When uploading files using PHP scripts, it is important to handle file permissions properly to ensure that the uploaded files are secure and accessible. One way to do this is by setting the correct file permissions after the file has been uploaded. This can be done using PHP's chmod function, which allows you to specify the desired permissions for the uploaded file.
// Upload file
$targetDir = "uploads/";
$targetFile = $targetDir . basename($_FILES["file"]["name"]);
if (move_uploaded_file($_FILES["file"]["tmp_name"], $targetFile)) {
// Set file permissions
chmod($targetFile, 0644);
echo "File uploaded successfully.";
} else {
echo "Error uploading file.";
}