Saturday, June 6
Friday, June 5
Check uploaded file is actually an image using PHP.
<?php
if (@getimagesize($_FILES["file"]["tmp_name"]) !== false) {
$destination = "uploads/" . $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"], $destination);
}
?>
Monday, June 1
Remove all characters except letters and numbers.
Receiving short codes in an app via URL query strings? Instead of using complex sanitization functions, this simple RegEx replace will get rid of all the junk in the input $string except for letters and numbers:
$clean_code = preg_replace('/[^\w]/', '', $string);
If you want more control over which character classes are
preserved, you can specify them explicitly:
$clean_code = preg_replace('/[^a-zA-Z0-9]/', '', $string);
Subscribe to:
Posts (Atom)