how to create directory of date and month durning file upload into php
Important Links
- VLE Insurance Process Flow
- RAP Registration Flow
- RAP and VLE INS POSP
- Life Insurance
- Life Insurance Renewal
- Motor Comprehensive
- Motor Third Party
- Personal Accident
- Fire and Allied Perils
- Health Insurance
- Pradhan Mantri Fasal Bima Yojana (PMFBY)
- NPS
- CSC Digipay Commission Chart
- HDFC Commission
- Axis Bank Commission
- UCO Bank Commission
- ICICI Bank Commission
- BOB Bank Commission
- BOI Bank Commission
- CBI Bank Commission
- LIFE INSURANCE RENEWAL HANDBOOK
- Difference Between CSC RAP Insurance And CSC VLE Insurance - Registration | Products | Commission
- LIC Commission
how to create directory of date and month durning file upload into php
To create a directory with the date and month during file upload in PHP, you can follow these steps:
- Set up the HTML form to handle file uploads:
html
<form action="upload.php" enctype="multipart/form-data" method="post">
<code>Select file to upload: <input name="fileToUpload" type="file" />
<input name="submit" type="submit" value="Upload File" /></code></form>
- Create the PHP script (upload.php) that will handle the file upload and directory creation:
php
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["fileToUpload"])) {
$targetDir = "uploads/"; // The base directory where files will be uploaded
$uploadDate = date("Y-m-d"); // Get the current date in the format 'YYYY-MM-DD'
$uploadMonth = date("F"); // Get the current month's name (e.g., January, February, etc.)
// Create a directory with the format 'YYYY/MM' (e.g., '2023/July')
$uploadDir = $targetDir . $uploadDate . "/" . $uploadMonth . "/";
// Check if the directory exists; if not, create it recursively
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
$targetFile = $uploadDir . basename($_FILES["fileToUpload"]["name"]);
// Check if the file was uploaded successfully
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $targetFile)) {
echo "The file " . basename($_FILES["fileToUpload"]["name"]) . " has been uploaded.";
}
else { echo "Sorry, there was an error uploading your file."; }
}
?>
In this example, the uploaded files will be stored in the "uploads" directory within subdirectories organized by date and month. For example, if you upload a file on July 25, 2023, it will be stored in "uploads/2023/July/".
Please ensure that the "uploads" directory has appropriate permissions (write access) to allow PHP to create subdirectories and store files. You can adjust the directory structure or naming convention based on your requirements. Additionally, it's essential to validate and sanitize user input when handling file uploads to enhance security.
Latest POst
- LPG Gas Subsidy Check by mobile number
- PMEGP Loan Aadhar Card Se
- E Shram Card Balance Check Number
- How to Migrate CentOS 7 to AlmaLinux 8
- How to Install WHM/cPanel in Almalinux?
- Install cPanel on Rocky Linux 9 Server
- How to Link Aadhaar with UAN
- How To Setup LVS (Linux Virtual Server) Load Balancer on Rocky Linux 8.5
- Setup Quick DNS Server On Rocky Linux 8.5 Using Dnsmasq
- How To Install Ruby on Rails with Mysql on Rocky Linux 8.5
Recent Updates
- LPG Gas Subsidy Check by mobile number
- PMEGP Loan Aadhar Card Se
- E Shram Card Balance Check Number
- How to Migrate CentOS 7 to AlmaLinux 8
- How to Install WHM/cPanel in Almalinux?
- Install cPanel on Rocky Linux 9 Server
- How to Link Aadhaar with UAN
- How To Setup LVS (Linux Virtual Server) Load Balancer on Rocky Linux 8.5
- Setup Quick DNS Server On Rocky Linux 8.5 Using Dnsmasq
- How To Install Ruby on Rails with Mysql on Rocky Linux 8.5
Haryana Goverment Schemes
- Old Age Samman Allowance
- Widow Pension Scheme
- Disability Pension Scheme
- Financial Assistance to Destitute Children Scheme
- Financial Assistance to Non School Going Disabled Children
- Allowance to Dwarfs
- Allowance to Eunuchs
- Rajiv Gandhi Pariwar Bima Yojna
- Post-Matric Scholarship
- Merit Cum Means
- Pre-Matric Scholarship
- About MMPSY
- MMPSY PPT
- MMPSY HINDI Manual
- MMPSY English Manual
- Premium Chart for PMMDY (Pension Plan)
- Parivar Pehchan Patra (PPP)
- Download Family ID
- PMSVANidhi Process Flow
- PM SVANidhi through CSCs
- About PMSYM
- PMSYM Morpho Setting
- PMSYM Creative & FAQ
- PMSYM Process Manual