0% found this document useful (0 votes)
2 views1 page

PHP File Upload Demo

The document provides an example of a PHP file upload system, consisting of an HTML form for file selection and a PHP script to handle the upload. The HTML form allows users to select a file and submit it to 'upload.php'. The PHP script checks for submission, creates an upload directory if it doesn't exist, and moves the uploaded file to that directory while providing feedback on the upload status.

Uploaded by

piyushnagar128
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

PHP File Upload Demo

The document provides an example of a PHP file upload system, consisting of an HTML form for file selection and a PHP script to handle the upload. The HTML form allows users to select a file and submit it to 'upload.php'. The PHP script checks for submission, creates an upload directory if it doesn't exist, and moves the uploaded file to that directory while providing feedback on the upload status.

Uploaded by

piyushnagar128
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

PHP File Upload Example

1. HTML Form (upload_form.html):


<!DOCTYPE html>
<html>
<head>
<title>File Upload Demo</title>
</head>
<body>
<h2>Upload a File</h2>
<form action="upload.php" method="post" enctype="multipart/form-data">
<label>Select file to upload:</label>
<input type="file" name="uploadedFile" required><br><br>
<input type="submit" name="submit" value="Upload">
</form>
</body>
</html>

2. PHP Script (upload.php):


<?php
if (isset($_POST['submit'])) {
$uploadDir = "uploads/";
$uploadFile = $uploadDir . basename($_FILES["uploadedFile"]["name"]);

// Check if directory exists, if not create it


if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0755, true);
}

// Move uploaded file


if (move_uploaded_file($_FILES["uploadedFile"]["tmp_name"], $uploadFile)) {
echo "The file " . htmlspecialchars(basename($_FILES["uploadedFile"]["name"])) .
" has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
} else {
echo "No file submitted.";
}
?>

You might also like