|
|
|
มีปัญหาอัพโหลดไฟล์ video ไม่ขึ้นครับรบกวนช่วยดูให้ทีครับ |
|
|
|
|
|
|
|
เมื่อทำการอัพโหลดแล้วไม่สามารถอัพโหลดไฟลได้ครับ ลองแก้ไขแล้วก้อยังเป็นครับรบกวนทีครับ
Code (JavaScript)
$('#file2').uploadify({
'buttonText' : 'BROWSE...',
'uploader' : '<?=PATH_URL?>/module/jquery/jquery.uploadify/uploadify.swf',
'script' : '<?=PATH_URL?>/module/upload2.php',
'cancelImg' : '<?=PATH_URL?>/module/jquery/jquery.uploadify/cancel.png',
'folder' : '<?=PATH_URL?>/content/upload/home_vdo',
'auto' : true,
'fileDataName' : 'file',
'onComplete' : function(event,ID,fileObj,response,data) {
if(response=="error"){
alert('ต้องเป็นไฟล์ mp4 เท่านั้น');
return;
}
var obj = '<br /><a href="/content/upload/home_vdo/'+response+'" target="_blank"><img src="<?=PATH_URL?>/images/view2.png" /></a><br />';
$("#view2").html(obj);
$("#file_upload2").val(response);
}
});
Code (PHP)
<div class="form-group">
<label>MP4</label>
<br />
<input type="file" id="file2" name="file2" />
<br />
<div id="view2">
<?php
if($vdo!=""){
?>
<a href="<?=PATH_URL?>/content/upload/home_vdo/<?=$vdo?>" target="_blank"><img src="<?=PATH_URL?>/images/view2.png" /></a>
<?php
}
?>
</div>
<input type="hidden" id="file_upload2" name="file_upload2" value="<?=$vdo?>" />
</div>
หน้า upload2.php
Code (PHP)
<?php
error_reporting(0);
if(!empty($_FILES)) {
$new_name = time();
$filename = $_FILES['file']['name'];
$name_arr = preg_split ("\.", basename($filename));
list($file_extension,$upload_filename) = array_reverse($name_arr);
$file_extension = strtolower($file_extension);
if($file_extension!="mp4"){
echo "error";
exit;
}
$new_name = $new_name.".".$file_extension;
$upload_file_arr['name'] = $new_name;
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $upload_file_arr['name'];
if(move_uploaded_file($_FILES['file']['tmp_name'],$targetFile)){
$file = $upload_file_arr['name'];
}
echo $file;
exit;
}
?>
Tag : PHP, HTML/CSS, JavaScript, Ajax, jQuery, CakePHP
|
|
|
|
|
|
Date :
2016-05-12 16:16:05 |
By :
bosprogammer1 |
View :
901 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error ??
|
|
|
|
|
Date :
2016-05-12 16:27:37 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลอง ajax upload ดูไหม
ตัวนี้บอก % upload complete ด้วย
Code (JavaScript)
function updateFile(file, parent) {
var content = file.get(0).files[0];
var formData = new FormData();
formData.append('Parent', parent);
formData.append('File', file);
if(file.size < 20971520) {
$.ajax({
dataType: 'json',
url: '/admin/content/updatefile',
type: 'post',
cache: false,
data: formData,
processData: false,
contentType: false,
error: function(xhr, ajaxOption, thrownError) {
$('#caption-' + id).addClass('text-danger');
$('#caption-' + id).html('<i class="fa fa-times-circle fa-fw"></i> Upload failed.');
$('#button-' + id).find('button').removeClass('disabled');
console.log(xhr.responseText);
console.log(thrownError);
},
beforeSend: function() {
$('#caption-' + id).html('<i class="fa fa-spinner fa-pulse"></i> Uploading... (<span id="progress-' + id + '">0</span>%)');
$('#button-' + id).find('button:first').remove();
$('#button-' + id).find('button:last').remove();
$('#button-' + id).find('button').removeClass('btn-default');
$('#button-' + id).find('button').removeClass('btn-background');
$('#button-' + id).find('button').addClass('btn-danger');
$('#button-' + id).find('button').addClass('disabled');
},
xhr: function(){
// get the native XmlHttpRequest object
var xhr = $.ajaxSettings.xhr() ;
// set the onprogress event handler
xhr.upload.onprogress = function(evt){ $('#progress-' + id).html(Math.ceil((evt.loaded / evt.total) * 100)); } ;
// set the onload event handler
xhr.upload.onload = function(){ $('#caption-' + id).html('<i class="fa fa-clock-o fa-fw"></i> Please wait...'); } ;
// return the customized object
return xhr ;
},
success: function(obj) {
$('#item-' + id).replaceWith(writeItem(obj));
}
});
}
else {
alert("File is to big");
}
}
|
|
|
|
|
Date :
2016-05-13 12:26:07 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|