top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to upload a file using php script?

+1 vote
How to upload a file using php script?
posted Jun 11, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Picked from the

File 1:

<!DOCTYPE html>

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">


File: upload.php

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

Let me know if it does not suffice

answer Jun 11, 2015 by Salil Agrawal
MR SALIL ELABORATE FOR ME THE USE OF foward slash in the above php script.
on $target_dir="uploads/";
Its the linux way of directory or file separator. I think in windows it is "\"
Similar Questions
+1 vote

I'm trying to find open source code which is a form with upload script allowing a user to fill in some fields of data, then pick a couple of documents to upload and finally submit the form.

The status bar will show progress insuring the user doesn't click out and close the browser etc allowing the documents to upload. Once completed it then emails the form results and the attachments to the predetermined email address.