PHP File Uploader Tutorial

Creator:
Michael4

This will learn you how to upload files on your website Here is the code



<?php 
    
echo "<form action='' method='post'> 
        <input type='file' name='file'><br/> 
        <input type='submit' name='submit' value='Upload File'></form>"

        if(isset(
$_POST["submit"])){ 
            
$filetm $_FILES['file']['tmp_name']; 
            
$file $_FILES['file']['name']; 
            
$dr "files/"
                if(
move_uploaded_file($filetm,$dr.$file)){ 
                    echo 
"File uploaded successfully<br/>Thank you for uploading the file"
            }              } 
?>

I will explain the code

echo "<form action='' method='post'> <input type='file' name='file'><br/> <input type='submit' name='submit' value='Upload File'></form>";

This will print out the form

if(isset($_POST["submit"])){ $filetm = $_FILES['file']['tmp_name']; $file = $_FILES['file']['name']; $dr = "files/";

If the Upload File button is clicked, it will then put the temporary file in a variable and the file name in a variable and it will put the directory of the file to be uploaded in a variable.

if(move_uploaded_file($filetm,$dr.$file)){ echo "You have uploaded the file successfully<br/>Thank you for uploading the file";

This will upload the file to the server and print a message saying you have uploaded the file successfully.

Thank you for reading my PHP Uploader tutorial Thank you Michael

Description:
This is a PHP Uploader tutorial

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options