Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Upload File In PHP ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 111
    Comment on it

    File uploads is not difficult, it is easy to upload files or Images to the particular Folder. But before uploading the files ,you have to configure "php.ini" File. So, Check your php.ini file and verify the file_uploads directive is set On.

    Syntax: file_uploads = On

    Create HTML form that allow users to choose File.

    <form action="upload.php" method="post" enctype="multipart/form-data">
        Image Path: <input type="file" name="UploadFile">
        <input type="submit" value="Upload Image" name="submit">
    </form>
    

    Note: form tag uses the POST attribute method and has an enctype attribute set to multipart/form-data. Without these attributes, the file upload will not work.

    Upload File PHP Script

       <?php
    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
    $uploadOk = 1;
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
    if(isset($_POST["submit"])) {
        $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
        if($check !== false) {
            echo "Upload File is an image - " . $check["mime"] . ".";
            $uploadOk = 1;
        } else {
            echo "File is not an image.";
            $uploadOk = 0;
        }
    }
    ?>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: