How to upload file in PHP?

31 Views

How to upload file in PHP?

By using move_uploaded_file() function we can upload file in PHP.The move_uploaded_file() function moves an uploaded file to a new location.

This function returns TRUE on success, or FALSE on failure.

 move_uploaded_file(file,newloc)
 
 <?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
?>

 

Tags:-
PHP