What is the purpose of the "move_uploaded_file" function in PHP upload scripts?
The "move_uploaded_file" function in PHP upload scripts is used to move an uploaded file to a new location on the server. This function helps to securely store uploaded files in a designated directory, preventing any potential security risks associated with allowing files to be stored in temporary locations.
<?php
$uploadDir = 'uploads/';
$uploadFile = $uploadDir . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) {
echo "File is valid, and was successfully uploaded.";
} else {
echo "Upload failed";
}
?>
Keywords
Related Questions
- What are the advantages and disadvantages of using PHP's DateTime class to manipulate dates compared to traditional date functions?
- What is the recommended directory structure for a website with PHP components?
- What steps should be taken to prevent unauthorized access and protect sensitive data in PHP databases?