|
|
|
ขอความอนุเคราะห์ครับ saveไฟล์แล้วขนาดได้ 0 และ ส่งคำสั่งแล้วมันไปปรากฏบนแทบ address bar |
|
|
|
|
|
|
|
อันนี้ ไฟล์ครับ
Code (PHP)
require_once("./conDB.php");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$uploadDir = "./dn/";
if (!file_exists($uploadDir . 'pdf')) {
mkdir($uploadDir . 'pdf', 0777, true);
}
if (!file_exists($uploadDir . 'img')) {
mkdir($uploadDir . 'img', 0777, true);
}
$inputField1 = $_POST['inputField1'];
$inputField2 = $_POST['inputField2'];
$inputField3 = $_POST['inputField3'];
$base64Data1 = $_POST['fileToUpload1'];
$base64Data2 = $_POST['fileToUpload2'];
// Extract the base64 data from the data URI แยกข้อมูล base64 ออกจาก URI ข้อมูล
list($type1, $base64Data1) = explode(';', $base64Data1);
list(, $base64Data1) = explode(',', $base64Data1);
list($type2, $base64Data2) = explode(';', $base64Data2);
list(, $base64Data2) = explode(',', $base64Data2);
// Convert base64 to binary แปลง base64 เป็นไบนารี่
$binaryData1 = base64_decode($base64Data1);
$binaryData2 = base64_decode($base64Data2);
// Generate unique filenames
$timestamp = time();
$fileName1 = $timestamp . "_uploaded_file1.pdf";
$fileName2 = $timestamp . "_uploaded_file2.jpg";
// Specify the file paths
$filePath1 = $uploadDir . 'pdf/' . $fileName1;
$filePath2 = $uploadDir . 'img/' . $fileName2;
// Write the binary data to the files
if (file_put_contents($filePath1, $binaryData1) !== false && file_put_contents($filePath2, $binaryData2) !== false) {
$txtall = ' Years : ' . $inputField1 . ' No : ' . $inputField2 . ' Issue : ' . $inputField3;
$strSQL = "INSERT INTO uploadhuj (description, name_cover, name_file, random_cover, random_file) VALUES
('$txtall', '$fileName2', '$fileName1', '$fileName2', '$fileName1')";
$objCon = mysqli_connect($host, $username, $password, $dbname);
mysqli_set_charset($objCon, "utf8");
$objQuery = mysqli_query($objCon, $strSQL);
echo "Files successfully uploaded. Additional Data 1: $txtall";
} else {
echo "Error uploading files.";
}
} else {
echo "Invalid request.";
}
|
|
|
|
|
Date :
2024-03-05 16:07:56 |
By :
Passto |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อันนี้ ไฟล์อัพโหลดไฟล์ครับ
Code (PHP)
<!DOCTYPE html>
<html>
<head>
<title>File Upload Form</title>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
</head>
<body>
<div id="result"></div>
<!-- HTML form for file upload -->
<form id="uploadForm">
<!-- Additional input fields -->
<input type="text" id="inputField1" name="inputField1" placeholder="Input field 1"><br>
<input type="text" id="inputField2" name="inputField2" placeholder="Input field 2"><br>
<input type="text" id="inputField3" name="inputField3" placeholder="Input field 3"><br>
<!-- File input fields -->
<input type="file" id="fileToUpload1" name="fileToUpload1"><br>
<input type="file" id="fileToUpload2" name="fileToUpload2"><br>
<button id="uploadButton">Upload</button>
</form>
<script>
$(document).ready(function() {
// Handle file upload using AJAX
$("#uploadButton").click(function() {
var formData = new FormData();
// Add additional input fields
formData.append('inputField1', $('#inputField1').val());
formData.append('inputField2', $('#inputField2').val());
formData.append('inputField3', $('#inputField3').val());
// Handle file input fields Read and encode file as Base64 before sending it to the server
for (var i = 1; i <= 2; i++) {
var fileInput = $('#fileToUpload' + i)[0];
if (fileInput.files.length > 0) {
var file = fileInput.files[0];
var reader = new FileReader();
reader.onload = function(e) {
formData.append('fileToUpload' + i, e.target.result);
// Perform AJAX request
$.ajax({
url: "newzzz.php",
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function(response) {
$("#result").html(response);
},
error: function(error) {
console.log("Error:", error);
}
});
};
reader.readAsDataURL(file);
}
}
});
});
</script>
</body>
</html>
|
|
|
|
|
Date :
2024-03-05 16:08:52 |
By :
Passto |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณไม่สามารถอ่านค่าจาก input file แบบนั้นได้
ให้ลองหาตัวอย่าง javascript ajax upload มาประยุกต์ทำ ในเว็บนี้ก็มี
|
|
|
|
|
Date :
2024-03-05 22:30:38 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|