|
|
|
รบกวนขอคำแนะนำด้วยครับ jQuery + PHP upload ไฟล์ไม่ได้ |
|
|
|
|
|
|
|
Code (PHP)
<form class="form-horizontal" id="quotation_attach" method="post" enctype="multipart/form-data">
<div class="control-group ">
<label class="control-label">Title</label>
<div class="controls">
<input class="span6 m-wrap" id="AttachName" name="AttachName" type="text" required/>
</div>
</div>
<div class="control-group">
<label class="control-label">Attach File</label>
<div class="controls">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="input-append">
<div class="uneditable-input">
<i class="icon-file fileupload-exists"></i>
<span class="fileupload-preview"></span>
</div>
<span class="btn btn-file">
<span class="fileupload-new">Select file</span>
<span class="fileupload-exists">Change</span>
<input type="file" class="default" name="AttachFile" id="AttachFile" required="required"/>
</span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>
</div>
<span class="label label-important">NOTE!</span>
<span>File type must be .pdf file only.</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Remark</label>
<div class="controls">
<textarea class="m-wrap span6" rows="3" id="AttachRemark" name="AttachRemark"></textarea>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn blue" name="btn-save" id="btn-save">Submit</button>
</div>
</form>
Code (JavaScript)
$(document).on('submit', '#quotation_attach', function() {
$("#btn-save").html('loading ... <img src="../../assets/img/loader.gif" />').attr("disabled", true);
$.ajax({
url: "process.php",
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData:false,
success: function(data){
$("#msg-alert").fadeOut();
$("#msg-alert").fadeIn('slow', function(){
$("#msg-alert").html(data);
$("#process_modal").modal("show");
$("#btn-save").html('<i class="icon-save"></i> Submit').attr("disabled", false);
});
}
});
return false;
});
Code (PHP)
if(isset($_FILES["AttachFile"])){
$temp = explode(".",$_FILES["AttachFile"]["tmp_name"]);
$AttachFile = base64_decode($_POST['QuotRef']).'_'.md5(date("U")).'.'.end($temp);
$file_dir = "attachment/".$AttachFile;
$data = array();
$data["attach_name"] = mysqli_real_escape_string($conn, $_POST['AttachName']);
$data["attach_file"] = $AttachFile;
$data["attach_remark"] = mysqli_real_escape_string($conn, $_POST['AttachRemark']);
$data["last_modify"] = $last_modify_user;
if(move_uploaded_file($_FILES["AttachFile"]["tmp_name"],$file_dir)){
$insert_attach = insert_data("tbl_attach",$data);
}
if($insert_attach)
{
echo $alert_complete;
}
else{
echo $alert_error;
}
}
Tag : PHP, MySQL, Ajax, jQuery, Linux
|
|
|
|
|
|
Date :
2016-07-28 21:25:49 |
By :
fourcasia |
View :
864 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (JavaScript)
e.preventDefault();
var formData = new FormData(this);
$.ajax({
type:'POST',
url: $(this).attr('action'),
data:formData,
cache:false,
contentType: false,
processData: false,
success:function(res){
console.log('sucess')
},
error: function(e){
alert("some thing error.");
}
});
|
|
|
|
|
Date :
2016-07-29 09:17:50 |
By :
โดย |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|