PDA

View Full Version : سوال: عوض کردن مقدیر پیش فرض تابع jquery



numberone1
دوشنبه 20 شهریور 1391, 10:12 صبح
سلام یه تابع jquery هست که یه سری مقادیر پیش فرض داره میخوام اینارو بتونم عوض کنم با php در حقیقت میخوام این امکان و به یوزر بدم که نوع فایل های آپلودی رو خودش تعیین کنه و سایز و خودش مشخص کنه و آدرس آپلود و ....... این کدش


$(function(){
$('#swfupload-control').swfupload({
upload_url: "upload-file.php",
file_post_name: 'uploadfile',
file_size_limit : "1024",
file_types : "*.jpg;*.png;*.gif",
file_types_description : "Image files",
file_upload_limit : 5,
flash_url : "js/swfupload/swfupload.swf",
button_image_url : 'js/swfupload/wdp_buttons_upload_114x29.png',
button_width : 114,
button_height : 29,
button_placeholder : $('#button')[0],
debug: false
})

azowghi
دوشنبه 20 شهریور 1391, 11:06 صبح
سلام
باید برای هر کدوم از چیزایی که میخوای کاربر تعیین کنه یک input با یک id یکتا بگذاری.

مثلا:

<input type=”text” id=”filetype”>

بعدش توی جی کوپری اینطور بنویسی:


$(function(){
var filetype= $(“#filetype”).val();
$('#swfupload-control').swfupload({
upload_url: "upload-file.php",
file_post_name: 'uploadfile',
file_size_limit : "1024",
file_types : filetype
file_types_description : "Image files",
file_upload_limit : 5,
flash_url : "js/swfupload/swfupload.swf",
button_image_url : 'js/swfupload/wdp_buttons_upload_114x29.png',
button_width : 114,
button_height : 29,
button_placeholder : $('#button')[0],
debug: false
})

numberone1
دوشنبه 20 شهریور 1391, 12:12 عصر
مرسی
اینجوری تغییرش دادم نشد
فایل gif هم آپلود شد


<input type=”text” id=”filetype” value="*.jpg">

$(function(){
var filetype= $("#filetype").val();
$('#swfupload-control').swfupload({
upload_url: "upload-file.php",
file_post_name: 'uploadfile',
file_size_limit : "1024",
file_types : filetype,
file_types_description : "Image files",
file_upload_limit : 5,
flash_url : "js/swfupload/swfupload.swf",
button_image_url : 'js/swfupload/wdp_buttons_upload_114x29.png',
button_width : 114,
button_height : 29,
button_placeholder : $('#button')[0],
debug: false
})

azowghi
دوشنبه 20 شهریور 1391, 12:27 عصر
یک دکمه ایجاد کنید:


<button id="button"></button>

بعد کد رو اینطور بذارید:


$('#button').click(function() {

var filetype= $(“#filetype”).val();
$('#swfupload-control').swfupload({
upload_url: "upload-file.php",
file_post_name: 'uploadfile',
file_size_limit : "1024",
file_types : filetype
file_types_description : "Image files",
file_upload_limit : 5,
flash_url : "js/swfupload/swfupload.swf",
button_image_url : 'js/swfupload/wdp_buttons_upload_114x29.png',
button_width : 114,
button_height : 29,
button_placeholder : $('#button')[0],
debug: false
});

});

numberone1
دوشنبه 20 شهریور 1391, 12:33 عصر
خودش یه button داره که اینه


<div id="swfupload-control">
<input type="button" id="button" />
<p id="queuestatus" ></p>
<ol id="log"></ol>
</div>

وقتی اولش اون کد شما رو میزارم دیگه قسمت فلش لود نمیشه و دکمه هم دیگه حالت browse خودشو از دست میده!!!

numberone1
دوشنبه 20 شهریور 1391, 12:41 عصر
بعد اگر بخوام ارور با استفاده از همین jquery بدم که فایل وجود داره چطور باید بهش اضافه کنم؟
قسمت کد php هیچ مشکلی نداره و توی صفحه upload-file.php هست ولی قسمت نمایش از طریق jquery رو چطور باید بهش اضافه کنم؟

numberone1
دوشنبه 20 شهریور 1391, 13:08 عصر
مشکل اولم حل شد ممنون
حالا اگه بخوام تشخیص بدم که فایلی که انتخاب شده برای آپلود قبلا آپلود شده و الان روی سرور وجود داره باید چطور اسم فایل و از jquery بگیرم بعد از اینکه با php بررسی کردم نتیجه رو دوباره بهش برگردونم
لطفا راهنمائی کنید ممنون

azowghi
دوشنبه 20 شهریور 1391, 13:30 عصر
سلام

آزاکس میشه:

$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});

numberone1
دوشنبه 20 شهریور 1391, 13:32 عصر
.bind('fileQueued', function(event, file){
var listitem='<li id="'+file.id+'" >'+
'File: <em>'+file.name+'</em> ('+Math.round(file.size/1024)+' KB) <span class="progressvalue" ></span>'+
'<div class="progressbar" ><div class="progress" ></div></div>'+
'<p class="status" >درحال ارسال</p>'+
'<span class="cancel" >&nbsp;</span>'+
'</li>';
$('#log').append(listitem);
$('li#'+file.id+' .cancel').bind('click', function(){
var swfu = $.swfupload.getInstance('#swfupload-control');
swfu.cancelUpload(file.id);
$('li#'+file.id).slideUp('fast');
});
// start the upload since it's queued
$(this).swfupload('startUpload');
})
.bind('fileQueueError', function(event, file, errorCode, message){
alert('اندازه این فایل '+file.name+' بیش از محدودیت تعیین شده است');
})
.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
$('#queuestatus').text('فایل های انتخاب شده: '+numFilesSelected+' / فایل های در انتظار: '+numFilesQueued);
})
.bind('uploadStart', function(event, file){
$('#log li#'+file.id).find('p.status').text('درحال بارگذاری');
$('#log li#'+file.id).find('span.progressvalue').text('0%' );
$('#log li#'+file.id).find('span.cancel').hide();
})
.bind('uploadProgress', function(event, file, bytesLoaded){
//Show Progress
var percentage=Math.round((bytesLoaded/file.size)*100);
$('#log li#'+file.id).find('div.progress').css('width', percentage+'%');
$('#log li#'+file.id).find('span.progressvalue').text(perc entage+'%');
})
.bind('uploadSuccess', function(event, file, serverData){
var item=$('#log li#'+file.id);
item.find('div.progress').css('width', '100%');
item.find('span.progressvalue').text('100%');
var pathtofile='<a href="uploads/'+file.name+'" target="_blank" >نمایش &raquo;</a>';
item.addClass('success').find('p.status').html('ب ا موفقیت انجام شد | '+pathtofile);
})
.bind('uploadComplete', function(event, file){
// upload has completed, try the next one in the queue
$(this).swfupload('startUpload');
})

});

</script>

numberone1
دوشنبه 20 شهریور 1391, 13:34 عصر
از توی کد بالا چطور میتونم اسم فایل انتخاب شده رو ارسال کنم برای یه صفحه php بصورت آجاکس یا با jquery؟؟

azowghi
دوشنبه 20 شهریور 1391, 13:42 عصر
اول این کار:


.bind('fileQueued', function(event, file){
var listitem='<li id="'+file.id+'" >'+
'File: <em>'+file.name+'</em> ('+Math.round(file.size/1024)+' KB) <span class="progressvalue" ></span>'+
'<div class="progressbar" ><div class="progress" ></div></div>'+
'<p class="status" >درحال ارسال</p>'+
'<span class="cancel" >&nbsp;</span>'+
'</li>';
$('#log').append(listitem);
$('li#'+file.id+' .cancel').bind('click', function(){
var swfu = $.swfupload.getInstance('#swfupload-control');
swfu.cancelUpload(file.id);
$('li#'+file.id).slideUp('fast');
});
// start the upload since it's queued
$(this).swfupload('startUpload');
})
.bind('fileQueueError', function(event, file, errorCode, message){
alert('اندازه این فایل '+file.name+' بیش از محدودیت تعیین شده است');
})
.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
$('#queuestatus').text('فایل های انتخاب شده: '+numFilesSelected+' / فایل های در انتظار: '+numFilesQueued);
})
.bind('uploadStart', function(event, file){
$('#log li#'+file.id).find('p.status').text('درحال بارگذاری');
$('#log li#'+file.id).find('span.progressvalue').text('0%' );
$('#log li#'+file.id).find('span.cancel').hide();
})
.bind('uploadProgress', function(event, file, bytesLoaded){
//Show Progress
var percentage=Math.round((bytesLoaded/file.size)*100);
$('#log li#'+file.id).find('div.progress').css('width', percentage+'%');
$('#log li#'+file.id).find('span.progressvalue').text(perc entage+'%');
})
.bind('uploadSuccess', function(event, file, serverData){
var item=$('#log li#'+file.id);
item.find('div.progress').css('width', '100%');
item.find('span.progressvalue').text('100%');
var pathtofile='<a href="uploads/'+file.name+'" target="_blank" >نمایش &raquo;</a>';
item.addClass('success').find('p.status').html('ب ا موفقیت انجام شد | '+pathtofile);
$("#filename").val(file.name) ;
})
.bind('uploadComplete', function(event, file){
// upload has completed, try the next one in the queue
$(this).swfupload('startUpload');
})

});

</script>


بعد توی صفحه این رو بذارید:

<input type="hidden" id="filename">


بعد توی کد آژاکس:

var filename= $("filename").val();
$.ajax({
type: "POST",
url: "some.php",
data: { filename: filename, location: "Boston" }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});

numberone1
دوشنبه 20 شهریور 1391, 13:53 عصر
کلا دیگه اسکریپت کار نمیکنه
قسمت فلش لود نمیشه

numberone1
دوشنبه 20 شهریور 1391, 13:56 عصر
کل اسکریپت رو براتون ضمیمه کردم تست کنید لطفا
فقط بشه بهش یک گزینه اضافه کرد که اگر اسم فایل تکراری بود جایگزین فایل قبلی بکنه یا نه
ممنون میشم

azowghi
دوشنبه 20 شهریور 1391, 21:38 عصر
تا اینجاش تونستم فعلا:


$(function(){


$('#swfupload-control').swfupload({
upload_url: "upload-file.php",
file_post_name: 'uploadfile',
file_size_limit : "1024",
file_types : "*.jpg;*.png;*.gif",
file_types_description : "Image files",
file_upload_limit : 5,
flash_url : "js/swfupload/swfupload.swf",
button_image_url : 'js/swfupload/wdp_buttons_upload_114x29.png',
button_width : 114,
button_height : 29,
button_placeholder : $('#button')[0],
debug: false
})


.bind('fileQueued', function(event, file){
$("#fname").val(file.name);
var ffff=file.name;

$.ajax({
type: "POST",
url: "scan.php",
data: { filename: ffff }
}).done(function( msg ) {

if(msg=='yes'){
alert('فایل قبلا آپلود شده است.');
return false;
}else{

}

});


var listitem='<li id="'+file.id+'" >'+
'File: <em>'+file.name+'</em> ('+Math.round(file.size/1024)+' KB) <span class="progressvalue" ></span>'+
'<div class="progressbar" ><div class="progress" ></div></div>'+
'<p class="status" >Pending</p>'+
'<span class="cancel" >&nbsp;</span>'+
'</li>';
$('#log').append(listitem);
$('li#'+file.id+' .cancel').bind('click', function(){
var swfu = $.swfupload.getInstance('#swfupload-control');
swfu.cancelUpload(file.id);
$('li#'+file.id).slideUp('fast');
});
// start the upload since it's queued
$(this).swfupload('startUpload');
})
.bind('fileQueueError', function(event, file, errorCode, message){
alert('Size of the file '+file.name+' is greater than limit');
})
.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
$('#queuestatus').text('Files Selected: '+numFilesSelected+' / Queued Files: '+numFilesQueued);
})
.bind('uploadStart', function(event, file){
$('#log li#'+file.id).find('p.status').text('Uploading...' );
$('#log li#'+file.id).find('span.progressvalue').text('0%' );
$('#log li#'+file.id).find('span.cancel').hide();
})
.bind('uploadProgress', function(event, file, bytesLoaded){
//Show Progress
var percentage=Math.round((bytesLoaded/file.size)*100);
$('#log li#'+file.id).find('div.progress').css('width', percentage+'%');
$('#log li#'+file.id).find('span.progressvalue').text(perc entage+'%');
})
.bind('uploadSuccess', function(event, file, serverData){
var item=$('#log li#'+file.id);
item.find('div.progress').css('width', '100%');
item.find('span.progressvalue').text('100%');
var pathtofile='<a href="uploads/'+file.name+'" target="_blank" >view &raquo;</a>';
item.addClass('success').find('p.status').html('Do ne!!! | '+pathtofile);




})
.bind('uploadComplete', function(event, file){
// upload has completed, try the next one in the queue
$(this).swfupload('startUpload');
})

});