|
|
|
ช่วยแนะนำหน่อยครับจะ upload รูปภาพแต่ upload ไม่ได้เป็นเพราอะไรครับ |
|
|
|
|
|
|
|
ีupload.php
Code (JavaScript)
<script>
$(document).on('submit','form',function(e){
e.preventDefault();
$form = $(this);
uploadImage($form);
});
function uploadImage($form){
$form.find('.progress-bar').removeClass('progress-bar-success')
.removeClass('progress-bar-danger');
var formdata = new FormData($form[0]);
var request = new XMLHttpRequest();
request.upload.addEventListener('progress',function(e){
var percent = Math.round(e.loaded/e.total * 100);
$form.find('.progress-bar').width(percent+'%').html(percent+'%');
});
request.addEventListener('load',function(e){
$form.find('.progress-bar').addClass('progress-bar-success').html('upload complete....');
});
request.open('post','save_upload.php');
request.send(formdata);
$form.on('click','.cancel',function(){
request.abort();
$form.find('.progress-bar')
.addClass('progress-bar-danger')
.removeClass('progress-bar-success')
.html('upload aborted....')
});
}
</script>
Code (PHP)
<form action="save_upload.php" method="post" enctype="multipart/form-data" class="form-horizontal">
<div class="form-group">
<input class="control-label col-sm-3" type="file" name="image">
<button class="btn btn-sm btn-info upload" type="submit">Upload</button>
<button type="button" class="btn btn-sm btn-danger cancel">Cancel</button>
</div>
<div class="progress progress-striped active">
<div class="progress-bar" style="width: 0%"></div>
</div>
</form>
Save_upload.php
Code (PHP)
<?php
error_reporting(0);
include ("module/inc/config.inc.php");
?>
<?php
if(isset($_POST['btn-upload']))
{
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder = "admin/upload_folder/";
$new_size =$file_size/1024;
$new_file_name = strtolower($file);
$final_file=str_repeat(' ','-','$new_file_name');
if(move_uploaded_file($file_loc, $folder.$final_file))
{
$sql="INSERT INTO tbl_uploads(file,type,size,subject,Teacher)
VALUES ('$final_file','$file_type','$new_size','".$_POST['txtName']."','".$_POST['txtteacher']."')";
mysql_query($conn,$sql);
mysql_query('SET NAMES UTF8');
?>
<script>
alert('อัพโหลดสำเร็จ');
window.location = "allfiles.php";
</script>
<?php
}
else
{
?>
<script>
alert('อัพโหลดไม่สำเร็จ');
window.location="upload.php";
</script>
<?php
}
}
?>
<!--
<?php
/** var_dump($_FILES);
$tmp_file = $_FILES['image']['tmp_name'];
$filename = $_FILES['image']['name'];
move_uploaded_file($tmp_file, 'upload_folder/'.$filename);
?>
**/
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2018-06-09 22:13:52 |
By :
witsarut_bell |
View :
756 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มี error อะไรรึป่าว ลอง inspect ใน google chrome (กด F12) มาดู ว่ามัน error อะไร
|
|
|
|
|
Date :
2018-06-09 23:23:02 |
By :
randOmizE |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|