Skip to content

Commit

Permalink
file upload code added
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhu007 committed Mar 9, 2024
1 parent c97c2df commit 5fcade2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
16 changes: 10 additions & 6 deletions file-upload/fileupload.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
<body>
<div class="container">
<h1>Multiple File Upload</h1>
<form action="/file-upload/upload.php" method="post" enctype="multipart/form-data">
<form action="/all_scripts/file-upload/upload.php" method="post" enctype="multipart/form-data">
<div class="mb-3">
<label for="file-input" class="form-label">Username:</label>
<input type="input" id="username" name="usernane" />
</div>
<div class="mb-3">
<label for="file-input" class="form-label">Select Files:</label>
<input type="file" id="files" name="files[]" multiple="multiple" />
Expand Down Expand Up @@ -57,18 +61,18 @@
$.fn.fileinputBsVersion = "3.3.7";
$("#files").fileinput({
theme: 'fas',
uploadUrl: '/file-upload/upload.php', // Replace with your actual upload URL
uploadUrl: '/all_scripts/file-upload/upload.php', // Replace with your actual upload URL
uploadAsync: false,
maxFileCount: 50,
allowedFileTypes: ['image', 'video', 'pdf'],
showUpload: false,
showRemove: false,
showUpload: true,
showRemove: true,
overwriteInitial: true,
previewFileType: 'any',
maxFileSize: 50000, // 50 MB in bytes
fileActionSettings: {
showUpload: false, // This also hides the upload icon
showRotate: false // Hides the rotate button
// showUpload: false, // This also hides the upload icon
showRotate: false, // Hides the rotate button
}
});
});
Expand Down
12 changes: 6 additions & 6 deletions file-upload/upload.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

// Define upload directory
$upload_dir = 'uploads/';
$uploadDir = 'uploads/';

// Check if upload directory exists
if (!is_dir($upload_dir)) {
mkdir($upload_dir, 0777, true);
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}

// Initialize response array
Expand All @@ -14,7 +14,7 @@
// Loop through uploaded files
foreach ($_FILES['files']['name'] as $key => $name) {
// Get file information
$tmp_name = $_FILES['files']['tmp_name'][$key];
$tmpName = $_FILES['files']['tmp_name'][$key];
$size = $_FILES['files']['size'][$key];
$type = $_FILES['files']['type'][$key];

Expand All @@ -27,7 +27,7 @@
}

// Check for file size
if ($size > 52428800) { // 1 MB limit
if ($size > 52428800) { // 50 MB limit
$response['files'][] = ['name' => $name, 'error' => 'File size too large.'];
continue;
}
Expand All @@ -36,7 +36,7 @@
$filename = uniqid() . '_' . $name;

// Upload file
if (move_uploaded_file($tmp_name, $upload_dir . $filename)) {
if (move_uploaded_file($tmpName, $uploadDir . $filename)) {
$response['files'][] = ['name' => $name, 'success' => 'File uploaded successfully.'];
// Store additional information about the uploaded file in a database or other storage
// ...
Expand Down

0 comments on commit 5fcade2

Please sign in to comment.