|
|
|
จะให้อัพโหลดไฟล์เป็นนามสกุล PDF อย่างเดียว ทำยังงัยคะ |
|
|
|
|
|
|
|
Code (PHP)
$file_type = $_FILES['fileUpload']['type']; //returns the mimetype
$allowed = array("image/jpeg", "image/gif", "application/pdf");
if(!in_array($file_type, $allowed)) {
$error_message = 'Only jpg, gif, and pdf files are allowed.';
}
|
|
|
|
|
Date :
2018-04-02 14:47:58 |
By :
xman |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
html:
<input type="file" id="file" onchange="return fileValidation()"/>
javascript:
Code (JavaScript)
function fileValidation(){
var fileInput = document.getElementById('file');
var filePath = fileInput.value;
var allowedExtensions = /(\.jpg|\.jpeg|\.png|\.gif)$/i;
if(!allowedExtensions.exec(filePath)){
alert('Please upload file having extensions .jpeg/.jpg/.png/.gif only.');
fileInput.value = '';
return false;
}else{
//Image preview
if (fileInput.files && fileInput.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
document.getElementById('imagePreview').innerHTML = '<img src="'+e.target.result+'"/>';
};
reader.readAsDataURL(fileInput.files[0]);
}
}
}
|
|
|
|
|
Date :
2018-04-02 14:51:01 |
By :
xman |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากคะ ทำได้แล้วคะ
|
|
|
|
|
Date :
2018-04-02 16:20:21 |
By :
pumhonda |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|