0% found this document useful (0 votes)
14 views

php pracital file (1)

The document contains multiple PHP programs that perform various mathematical and logical operations, including arithmetic calculations, area calculations for different shapes, solving quadratic equations, checking triangle types, generating multiplication tables, calculating sums of natural numbers, printing Fibonacci series, finding factorials, identifying prime numbers, and computing student grades. Each program includes HTML forms for user input and displays the results on the same page. The document is structured as a series of individual tasks, each with its own code snippet.

Uploaded by

rs1559353
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

php pracital file (1)

The document contains multiple PHP programs that perform various mathematical and logical operations, including arithmetic calculations, area calculations for different shapes, solving quadratic equations, checking triangle types, generating multiplication tables, calculating sums of natural numbers, printing Fibonacci series, finding factorials, identifying prime numbers, and computing student grades. Each program includes HTML forms for user input and displays the results on the same page. The document is structured as a series of individual tasks, each with its own code snippet.

Uploaded by

rs1559353
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Q1.

Take values from the user and compute sum, subtraction, multiplication, division and exponent
of value of the variables

<!DOCTYPE html>

<html>

<head>

<title>Arithmetic Operations in PHP</title>

</head>

<body>

<form method="post">

<label for="num1">Enter first number:</label>

<input type="number" id="num1" name="num1" required><br><br>

<label for="num2">Enter second number:</label>

<input type="number" id="num2" name="num2" required><br><br>

<input type="submit" name="submit" value="Calculate">

</form>

<?php

if (isset($_POST['submit'])) {

$num1 = $_POST['num1'];

$num2 = $_POST['num2'];

$sum = $num1 + $num2;

$subtraction = $num1 - $num2;

$multiplication = $num1 * $num2;

$division = $num1 / $num2;

$exponent = $num1 ** $num2;

echo "<h2>Results:</h2>";

echo "Sum: " . $sum . "<br>";

echo "Subtraction: " . $subtraction . "<br>";

echo "Multiplication: " . $multiplication . "<br>";

echo "Division: " . $division . "<br>";

echo "Exponentiation: " . $exponent . "<br>";


echo "Name:Manish Class:BCA5B <br>";

?>

</body>

</html>
Q2.Write a program to find area of following shapes: circle, rectangle, triangle, square, trapezoid and
parallelogram.

<!DOCTYPE html>

<html lang="en">

<head> <meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document</title>

</head><body>

<?php

//area of circle

$radius=8;

$area=3.14*$radius*$radius;

echo " <br> area of circle is : $area";

//area of rectangle

$length=7;

$breadth=8;

$area= $length*$breadth;

echo " <br> area of rectangle is : $area";

//area of triangle

$base=3;$height=4;

$area=1/2*$base*$height;

echo " <br> area of triangle is: $area";

//area of square

$sides=9;

$area=$sides*$sides;

echo " <br> area of square is : $area";

//area of parallelogram

$a=10;$b=11;

$area=$a*$b;

echo " <br> area of parallelogram is : $area";

//area of trapezium
$c=5;$d=6;

$area=1/2*($c+$d)*10;

echo " <br> area of trapezium is : $area";

echo "<br>";

echo "Name:Manish Class:BCA5B <br>";

?>

</body>

</html>
Q3.Compute and print roots of quadratic equation.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Quadratic Equation Solver</title>

</head>

<body>

<h1>Quadratic Equation Solver</h1>

<form method="post">

<label for="a">Enter a (coefficient of x²):</label>

<input type="number" name="a" required step="any"><br><br>

<label for="b">Enter b (coefficient of x):</label>

<input type="number" name="b" required step="any"><br><br>

<label for="c">Enter c (constant):</label>

<input type="number" name="c" required step="any"><br><br>

<input type="submit" value="Calculate Roots">

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$a = $_POST['a'];

$b = $_POST['b'];

$c = $_POST['c'];

// Calculate the discriminant

$discriminant = $b * $b - 4 * $a * $c;

// Check the nature of the roots

if ($discriminant > 0) {

// Two distinct real roots

$root1 = (-$b + sqrt($discriminant)) / (2 * $a);

$root2 = (-$b - sqrt($discriminant)) / (2 * $a);


echo "<h2>Roots are real and distinct:</h2>";

echo "Root 1: " . $root1 . "<br>";

echo "Root 2: " . $root2 . "<br>";

} elseif ($discriminant == 0) {

// One double real root

$root = -$b / (2 * $a);

echo "<h2>Roots are real and the same:</h2>";

echo "Root: " . $root . "<br>";

} else {

// Complex roots

$realPart = -$b / (2 * $a);

$imaginaryPart = sqrt(-$discriminant) / (2 * $a);

echo "<h2>Roots are complex:</h2>";

echo "Root 1: " . $realPart . " + " . $imaginaryPart . "i<br>";

echo "Root 2: " . $realPart . " - " . $imaginaryPart . "i<br>";

?>

</body>

</html>
Q4.Write a program to determine whether a triangle is isosceles or not?

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Triangle Type Checker</title>

</head>

<body>

<h1>Isosceles Triangle Checker</h1>

<form method="post">

<label for="side1">Enter length of side 1:</label>

<input type="number" name="side1" required step="any"><br><br>

<label for="side2">Enter length of side 2:</label>

<input type="number" name="side2" required step="any"><br><br>

<label for="side3">Enter length of side 3:</label>

<input type="number" name="side3" required step="any"><br><br>

<input type="submit" value="Check Triangle Type">

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$side1 = $_POST['side1'];

$side2 = $_POST['side2'];

$side3 = $_POST['side3'];

// Check if the triangle is isosceles

if ($side1 <= 0 || $side2 <= 0 || $side3 <= 0) {

echo "<h2>Please enter valid positive lengths for the sides.</h2>";

} elseif ($side1 == $side2 || $side2 == $side3 || $side1 == $side3) {

echo "<h2>The triangle is isosceles.</h2>";

} else {

echo "<h2>The triangle is not isosceles.</h2>";


}

?>

</body>

</html>
Q5.Print multiplication table of a number input by the user.

<form method="post">

<input type="number" name="num" placeholder="Number" required>

<input type="number" name="limit" placeholder="Limit" required>

<button type="submit">Print Table</button>

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$num = $_POST['num'];

$limit = $_POST['limit'];

echo "<h2>Multiplication Table of $num</h2>";

for ($i = 1; $i <= $limit; $i++) {

echo "$num x $i = $num * $i<br>";

?>
Q6.Calculate sum of natural numbers from one to n number.

<form method="post">

<input type="number" name="n" placeholder="Number" required>

<button type="submit">Calculate Sum</button>

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$n = $_POST['n'];

$sumFormula = ($n * ($n + 1)) / 2;

echo "Sum using formula: $sumFormula<br>";

$sumLoop = 0;

for ($i = 1; $i <= $n; $i++) {

$sumLoop += $i;

echo "Sum using loop: $sumLoop<br>";

$sumArray = array_sum(range(1, $n));

echo "Sum using array_sum and range: $sumArray";

?>
Q7.Print Fibonacci series up to n numbers e.g. 0 1 1 2 3 5 8 13 21…..n.

<form method="post">

<input type="number" name="n" placeholder="Number" required>

<button type="submit">Print Fibonacci Series</button>

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$n = $_POST['n'];

echo "Fibonacci Series using loop:<br>";

$num1 = 0;

$num2 = 1;

echo "$num1 $num2 ";

for ($i = 3; $i <= $n; $i++) {

$num3 = $num1 + $num2;

echo "$num3 ";

$num1 = $num2;

$num2 = $num3;

echo "<br>";

echo "Fibonacci Series using recursive function:<br>";

function fibonacci($n) {

if ($n == 0) {

return 0;

} elseif ($n == 1) {

return 1;

} else {

return fibonacci($n - 1) + fibonacci($n - 2);

for ($i = 0; $i < $n; $i++) {

echo fibonacci($i) . " ";


}

echo "<br>";

echo "Fibonacci Series using array:<br>";

$fibArray = array(0, 1);

while (count($fibArray) < $n) {

$fibArray[] = $fibArray[count($fibArray) - 1] + $fibArray[count($fibArray) - 2];

echo implode(" ", $fibArray);

?>
Q8.Write a program to find the factorial of any number.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Factorial Calculator</title>

</head>

<body>

<h1>Factorial Calculator</h1>

<form method="post">

<label for="number">Enter a non-negative integer:</label>

<input type="number" name="number" required min="0"><br><br>

<input type="submit" value="Calculate Factorial">

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$number = $_POST['number'];

function factorial($n) {

if ($n == 0 || $n == 1) {

return 1;

} else {

return $n * factorial($n - 1);

$result = factorial($number);

echo "<h2>Factorial of $number is $result.</h2>";

?>

</body>

</html>
Q9.Determine prime numbers within a specific range.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Prime Number Finder</title>

</head>

<body>

<h1>Prime Number Finder</h1>

<form method="post">

<label for="start">Enter the start of the range:</label>

<input type="number" name="start" required><br><br>

<label for="end">Enter the end of the range:</label>

<input type="number" name="end" required><br><br>

<input type="submit" value="Find Prime Numbers">

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$start = $_POST['start'];

$end = $_POST['end'];

if ($start < 2 || $end < 2 || $start > $end) {

echo "<h2>Please enter a valid range (both numbers must be >= 2 and start <= end).</h2>";

} else {

echo "<h2>Prime numbers between $start and $end:</h2>";

$primeNumbers = [];

for ($num = $start; $num <= $end; $num++) {

if (isPrime($num)) {

$primeNumbers[] = $num;

}
if (empty($primeNumbers)) {

echo "No prime numbers found in this range.";

} else {

echo implode(", ", $primeNumbers);

function isPrime($num) {

if ($num <= 1) return false;

if ($num <= 3) return true;

if ($num % 2 == 0 || $num % 3 == 0) return false;

for ($i = 5; $i * $i <= $num; $i += 6) {

if ($num % $i == 0 || $num % ($i + 2) == 0) {

return false;

return true;

?>

</body>

</html>
Q10.Write a program to compute, the Average and Grade of students marks.

<form method="post">

<label>Student Name: <input type="text" name="name" required></label><br>

<label>Subject 1 Marks: <input type="number" name="sub1" required></label><br>

<label>Subject 2 Marks: <input type="number" name="sub2" required></label><br>

<label>Subject 3 Marks: <input type="number" name="sub3" required></label><br>

<button type="submit">Calculate Average and Grade</button>

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$name = $_POST['name'];

$sub1 = $_POST['sub1'];

$sub2 = $_POST['sub2'];

$sub3 = $_POST['sub3'];

$average = ($sub1 + $sub2 + $sub3) / 3;

if ($average >= 90) {

$grade = 'A';

} elseif ($average >= 80) {

$grade = 'B';

} elseif ($average >= 70) {

$grade = 'C';

} elseif ($average >= 60) {

$grade = 'D';

} else {

$grade = 'F';

echo "<h2>Student Report Card</h2>";

echo "<p>Name: $name</p>";

echo "<p>Subject 1 Marks: $sub1</p>";

echo "<p>Subject 2 Marks: $sub2</p>";

echo "<p>Subject 3 Marks: $sub3</p>";


echo "<p>Average Marks: $average</p>";

echo "<p>Grade: $grade</p>";

?>
Q11.Compute addition, subtraction and multiplication of a matrix.

<form method="post">

<label>Matrix A Rows: <input type="number" name="rowsA" required></label><br>

<label>Matrix A Columns: <input type="number" name="colsA" required></label><br>

<label>Matrix B Rows: <input type="number" name="rowsB" required></label><br>

<label>Matrix B Columns: <input type="number" name="colsB" required></label><br>

<label>Matrix A Elements (space separated):<br>

<textarea name="matrixA" required></textarea>

</label><br>

<label>Matrix B Elements (space separated):<br>

<textarea name="matrixB" required></textarea>

</label><br>

<button type="submit">Compute Matrix Operations</button>

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$rowsA = $_POST['rowsA'];

$colsA = $_POST['colsA'];

$rowsB = $_POST['rowsB'];

$colsB = $_POST['colsB'];

$matrixA = explode(" ", $_POST['matrixA']);

$matrixB = explode(" ", $_POST['matrixB']);

// Reshape matrices

$matrixA = array_chunk($matrixA, $colsA);

$matrixB = array_chunk($matrixB, $colsB);

// Display matrices

echo "<h2>Matrix A:</h2>";

printMatrix($matrixA);

echo "<h2>Matrix B:</h2>";

printMatrix($matrixB);
// Matrix addition

if ($rowsA == $rowsB && $colsA == $colsB) {

echo "<h2>Matrix A + Matrix B:</h2>";

printMatrix(addMatrix($matrixA, $matrixB));

} else {

echo "Matrix addition not possible due to different dimensions.";

// Matrix subtraction

if ($rowsA == $rowsB && $colsA == $colsB) {

echo "<h2>Matrix A - Matrix B:</h2>";

printMatrix(subtractMatrix($matrixA, $matrixB));

} else {

echo "Matrix subtraction not possible due to different dimensions.";

// Matrix multiplication

if ($colsA == $rowsB) {

echo "<h2>Matrix A * Matrix B:</h2>";

printMatrix(multiplyMatrix($matrixA, $matrixB));

} else {

echo "Matrix multiplication not possible due to incompatible dimensions.";

// Function to print matrix

function printMatrix($matrix) {

foreach ($matrix as $row) {

echo implode(" ", $row) . "<br>";

// Function to add matrices

function addMatrix($matrixA, $matrixB) {

$result = array();
for ($i = 0; $i < count($matrixA); $i++) {

$row = array();

for ($j = 0; $j < count($matrixA[0]); $j++) {

$row[] = $matrixA[$i][$j] + $matrixB[$i][$j];

$result[] = $row;

return $result;

function subtractMatrix($matrixA, $matrixB) {

$result = array();

for ($i = 0; $i < count($matrixA); $i++) {

$row = array();

for ($j = 0; $j < count($matrixA[0]); $j++) {

$row[] = $matrixA[$i][$j] - $matrixB[$i][$j];

$result[] = $row;

return $result;

function multiplyMatrix($matrixA, $matrixB) {

$result = array();

for ($i = 0; $i < count($matrixA); $i++) {

$row = array();

for ($j = 0; $j < count($matrixB[0]); $j++) {

$sum = 0;

for ($k = 0; $k < count($matrixA[0]); $k++) {

$sum += $matrixA[$i][$k] * $matrixB[$k][$j];

$row[] = $sum;

$result[] = $row;
}

return $result;

?>
Q12.Count total number of vowels in a word “Develop & Empower Individuals”.

<?php

function countVowels($string) {

$string = strtolower($string);

preg_match_all('/[aeiou]/', $string, $matches);

return count($matches[0]);

$word = "Develop & Empower Individuals";

$totalVowels = countVowels($word);

echo "Total number of vowels: " . $totalVowels;

echo "<br>";

echo "Name:Manish Class:BCA5B <br>";

?>
Q13.Determine whether a string is palindrome or not?

<form method="post">

<label>Enter String: <input type="text" name="str" required></label><br>

<button type="submit">Check Palindrome</button>

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$str = $_POST['str'];

if (strrev($str) == $str) {

echo "$str is a palindrome.";

} else {

echo "$str is not a palindrome.";

echo "<br>";

$isPalindrome = true;

$len = strlen($str);

for ($i = 0; $i < $len / 2; $i++) {

if ($str[$i] != $str[$len - $i - 1]) {

$isPalindrome = false;

break;

if ($isPalindrome) {

echo "$str is a palindrome.";

} else {

echo "$str is not a palindrome.";

echo "<br>";

function isPalindromeRec($str, $start, $end) {

if ($start >= $end) {

return true;
}

if ($str[$start] != $str[$end]) {

return false;

return isPalindromeRec($str, $start + 1, $end - 1);

if (isPalindromeRec($str, 0, strlen($str) - 1)) {

echo "$str is a palindrome.";

} else {

echo "$str is not a palindrome.";

?>
Q14.Display word after Sorting in alphabetical order.

<form method="post">

<label>Enter Words (comma separated): <input type="text" name="words" required></label><br>

<button type="submit">Sort Words</button>

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$words = $_POST['words'];

$words = trim(strtolower($words));

$wordArray = explode(",", $words);

$wordArray = array_filter($wordArray);

$wordArray = array_map('trim', $wordArray);

sort($wordArray);

echo "Sorted Words (sort): " . implode(", ", $wordArray);

echo "<br>";

natcasesort($wordArray);

echo "Sorted Words (natcasesort): " . implode(", ", $wordArray);

echo "<br>";

?>
Q15.Check whether a number is in a given range using functions.

<form method="post">

<label>Enter Number: <input type="number" name="num" required></label><br>

<label>Min Value: <input type="number" name="min" required></label><br>

<label>Max Value: <input type="number" name="max" required></label><br>

<button type="submit">Check Range</button>

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$num = $_POST['num'];

$min = $_POST['min'];

$max = $_POST['max'];

function checkRange($num, $min, $max) {

if ($num >= $min && $num <= $max) {

return true;

} else {

return false;

if (checkRange($num, $min, $max)) {

echo "$num is within the range [$min, $max].";

} else {

echo "$num is not within the range [$min, $max].";

echo "<br>";

function isInRange($num, $min, $max) {

return ($num >= $min && $num <= $max) ? true : false;

if (isInRange($num, $min, $max)) {

echo "$num is within the range [$min, $max].";

} else {
echo "$num is not within the range [$min, $max].";

echo "<br>";

function checkNumberRange($num, $min, $max) {

if ($num < $min) {

echo "$num is less than $min.";

} elseif ($num > $max) {

echo "$num is greater than $max.";

} else {

echo "$num is within the range [$min, $max].";

checkNumberRange($num, $min, $max);

?>
Q16.Write a program accepts a string and calculates number of upper case letters and lower case
letters available in that string.

<form method="post">

<label>Enter String: <input type="text" name="str" required></label><br>

<button type="submit">Calculate Case</button>

</form>

<?php

// Echo statements for Name and Class

echo "<br>";

echo "Name: Manish Class: BCA5B <br>";

?>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$str = $_POST['str'];

$upper = 0;

$lower = 0;

for ($i = 0; $i < strlen($str); $i++) {

$char = $str[$i];

if (ctype_upper($char)) {

$upper++;

} elseif (ctype_lower($char)) {

$lower++;

echo "Upper Case Letters: $upper<br>";

echo "Lower Case Letters: $lower<br>";

$upper = preg_match_all('/[A-Z]/', $str);

$lower = preg_match_all('/[a-z]/', $str);

echo "Upper Case Letters: $upper<br>";

echo "Lower Case Letters: $lower<br>";


$chars = str_split($str);

$counts = array_count_values($chars);

$upper = array_sum(array_intersect_key($counts, array_flip(range('A', 'Z'))));

$lower = array_sum(array_intersect_key($counts, array_flip(range('a', 'z'))));

echo "Upper Case Letters: $upper<br>";

echo "Lower Case Letters: $lower<br>";

?>
Q17.Design a program to reverse a string word by word.

<!DOCTYPE html>

<html>

<head>

<title>String Reversal</title>

</head>

<body>

<form method="post">

<label>Enter String: <input type="text" name="str" required></label><br>

<button type="submit">Reverse String</button>

</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$str = $_POST['str'];

$words = explode(" ", $str);

$reversed = implode(" ", array_reverse($words));

echo "Original String: $str<br>";

echo "Reversed String: $reversed";

?>

</body>

</html>
Q18.Write a program to create a login form. On submitting the form, the user should navigate to
profile page.

<!DOCTYPE html>

<html>

<head>

<title>Login Form</title>

</head>

<body>

<h2>Login Form</h2>

<form method="post">

<label>Username: <input type="text" name="username" required></label><br>

<label>Password: <input type="password" name="password" required></label><br>

<button type="submit">Login</button>

</form>

<?php

session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$username = $_POST['username'];

$password = $_POST['password'];

// Validate credentials (replace with actual database validation)

if ($username == "admin" && $password == "password") {

$_SESSION['logged_in'] = true;

$_SESSION['username'] = $username;

header("Location: profile.php");

exit;

} else {

echo "Invalid credentials.";

?>
</body>

</html>
Q19.Design front page of a college or department using graphics method

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Department of Computer Science</title>

<style>

body { font-family: Arial, sans-serif; background: #f4f4f4; }

header { background: #007BFF; color: white; padding: 20px; text-align: center; }

nav a { margin: 0 10px; color: white; text-decoration: none; }

.container { width: 80%; margin: auto; padding: 20px; background: white; }

footer { text-align: center; padding: 10px; background: #007BFF; color: white; }

</style>

</head>

<body>

<header>

<h1>Department of Computer Science</h1>

<nav>

<a href="#">Home</a>

<a href="#">About</a>

<a href="#">Courses</a>

</nav>

</header>

<div class="container">

<h2>Welcome!</h2>

<p>We offer a range of courses to prepare students for careers in technology.</p>

<img src="department_image.jpg" alt="Department" style="width:100%; height:auto;">

</div>

<footer>
<p>&copy; 2024 Department of Computer Science</p>

</footer>

</body>

</html>
Q20.Write a program to upload and download files.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>File Upload and Download</title>

<style>

body { font-family: Arial, sans-serif; margin: 20px; }

form { margin-bottom: 20px; }

</style>

</head>

<body>

<h2>Upload File</h2>

<form action="" method="post" enctype="multipart/form-data">

<input type="file" name="fileToUpload" required>

<button type="submit" name="upload">Upload</button>

</form>

<?php

$targetDir = "uploads/"; // Directory to save uploaded files

if (isset($_POST['upload'])) {

$targetFile = $targetDir . basename($_FILES["fileToUpload"]["name"]);

$uploadOk = 1;

$fileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));

// Check if file already exists

if (file_exists($targetFile)) {

echo "Sorry, file already exists.<br>";

$uploadOk = 0;

if ($_FILES["fileToUpload"]["size"] > 2000000) {

echo "Sorry, your file is too large.<br>";


$uploadOk = 0;

if(!in_array($fileType, ['jpg', 'png', 'gif', 'pdf', 'txt'])) {

echo "Sorry, only JPG, PNG, GIF, PDF & TXT files are allowed.<br>";

$uploadOk = 0;

if ($uploadOk == 0) {

echo "Sorry, your file was not uploaded.<br>";

} else {

// Try to upload file

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $targetFile)) {

echo "The file ". htmlspecialchars(basename($_FILES["fileToUpload"]["name"])). " has been


uploaded.<br>";

} else {

echo "Sorry, there was an error uploading your file.<br>";

echo "<h2>Available Files for Download</h2>";

if (is_dir($targetDir)) {

if ($dh = opendir($targetDir)) {

while (($file = readdir($dh)) !== false) {

if ($file != "." && $file != "..") {

echo "<a href='$targetDir$file' download>$file</a><br>";

closedir($dh);

} else {

mkdir($targetDir); // Create uploads directory if it doesn't exist

}
?>

</body>

</html>

You might also like