Write a program to upload a file in PHP?

devquora
devquora

Posted On: Jun 05, 2021

 

The program to upload a file in PHP is as follows:

<?php

$target_dir = "uploads/";

$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);

$uploadOk = 1;

$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

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;

  }

}

?>

 

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    PHP Logical & Programming Interview Questions

    Write a program in Php to check whether a number is prime or not?

    The program in Php to check whether a number is prime or not is as follows : &lt;?php function primeCheck($number){ &nbsp; &nbsp; if ($number == 1) &nbsp; &nbsp; return 0; &nbsp; &nbsp; for ($i =...

    PHP Logical & Programming Interview Questions

    Write a program to find no of days between two dates in Php?

    The program to find no of days between two dates in PHP is as follows: Let the dates are 25-09-2020 and 31-01-2021 &lt;?php&nbsp;&nbsp; function dateDiffInDays($date1, $date2)&nbsp; { &nbsp; &nbs...

    PHP Logical & Programming Interview Questions

    Write a program in PHP to find the occurrence of a word in a string?

    The program in PHP to find the occurrence of a word in a string is as follows: &lt;?php $s1 = "interviewmocks.com is a interview prep site"; $s2 = "interview"; $res = substr_count($s1, $s2); echo...