Answer the question
In order to leave comments, you need to log in
How does the move_uploaded_file() function help protect against file upload attacks?
Hello! I found this example in the php documentation:
<?php
// В PHP 4.1.0 и более ранних версиях следует использовать $HTTP_POST_FILES
// вместо $_FILES.
$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "Файл корректен и был успешно загружен.\n";
} else {
echo "Возможная атака с помощью файловой загрузки!\n";
}
echo 'Некоторая отладочная информация:';
print_r($_FILES);
print "</pre>";
?>
echo "Возможная атака с помощью файловой загрузки!\n";
Answer the question
In order to leave comments, you need to log in
This check:
- protects against transferring your config with database passwords to the download folder. For example, with /upload.php?$_FILES[userfile][tmp_name]=../private/config.php&$_FILES[userfile]['name]=public_config.txt
- does not protect against loading a php script instead of a jpg file . This requires other checks and protections.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question