How can the move_uploaded_file function be used effectively in PHP to save uploaded files to a specific directory?
To save uploaded files to a specific directory in PHP, you can use the move_uploaded_file function. This function moves an uploaded file to a new location. To use it effectively, you need to specify the temporary file path of the uploaded file and the destination directory where you want to save it.
$uploadedFile = $_FILES['file']['tmp_name'];
$destination = 'uploads/' . $_FILES['file']['name'];
if (move_uploaded_file($uploadedFile, $destination)) {
echo "File uploaded successfully.";
} else {
echo "Failed to upload file.";
}
Related Questions
- Are there any security vulnerabilities in the provided PHP code for CAPTCHA generation and validation?
- In the provided PHP script, what potential pitfalls or errors could arise from using functions like sql_fetch_row() without proper definition?
- What is the purpose of the chop() function in PHP and how does it differ from other string manipulation functions?