PDA

View Full Version : آموزش: اپلودر jQuery File Upload Plugin در صفحه وب(انتخاب چندین فایل در یک browse)



hamed_hossani
جمعه 10 آذر 1391, 19:19 عصر
سلام

دمو (http://blueimp.github.com/jQuery-File-Upload/)

در این قسمت اگه وقت کنم اموزش می گذارم.

Features
Multiple file upload:
Allows to select multiple files at once and upload them simultaneously.
Drag & Drop support:
Allows to upload files by dragging them from your desktop or filemanager and dropping them on your browser window.
Upload progress bar:
Shows a progress bar indicating the upload progress for individual files and for all uploads combined.
Cancelable uploads:
Individual file uploads can be canceled to stop the upload progress.
Resumable uploads:
Aborted uploads can be resumed with browsers supporting the Blob API.
Chunked uploads:
Large files can be uploaded in smaller chunks with browsers supporting the Blob API.
Client-side image resizing:
Images can be automatically resized on client-side with browsers supporting the required JS APIs.
Preview images:
A preview of image files can be displayed before uploading with browsers supporting the required JS APIs.
No browser plugins (e.g. Adobe Flash) required:
The implementation is based on open standards like HTML5 and JavaScript and requires no additional browser plugins.
Graceful fallback for legacy browsers:
Uploads files via XMLHttpRequests if supported and uses iframes as fallback for legacy browsers.
HTML file upload form fallback:
Shows a standard HTML file upload form if JavaScript is disabled.
Cross-site file uploads:
Supports uploading files to a different domain with Cross-site XMLHttpRequests.
Multiple plugin instances:
Allows to use multiple plugin instances on the same webpage.
Customizable and extensible:
Provides an API to set individual options and define callBack methods for various upload events.
Multipart and file contents stream uploads:
Files can be uploaded as standard "multipart/form-data" or file contents stream (HTTP PUT file upload).
Compatible with any server-side application platform:
Works with any server-side platform (PHP, Python, Ruby on Rails, Java, Node.js, Go etc.) that supports standard HTML form file uploads.

منبع:
https://github.com/maxpavlov/jQuery-File-Upload.MVC3/downloads
https://github.com/i-e-b/jQueryFileUpload.Net/downloads
------------------------------------------------------------------------------------------
نحوه استفاده:
باید در 4 .net باشه
من پوشه ای ب نام jqueryFileUpload در app-code ساختم و فایل های ashx.cs را درونش کپی کردم و در

<%@ WebHandler Language="C#‎‎‎‎‎‎‎" CodeBehind="jqueryFileUpload/FileTransferHandler.ashx.cs" Class="jQueryUploadTest.FileTransferHandler" %>

codeBehine را تغییر دادم
مسیر StorageRoot در فایل FileTransferHandler.ashx.cs برای ذخیره کردن فایلها مورد استفاده قرار میگیره

public string StorageRoot
{
get
{
//writed by hamed.hossani@gmail.com
return HttpContext.Current.Server.MapPath("~/files/");
// ConfigurationManager.AppSettings["StorageRoot"];
}
}
مسیر HandlerPath در FilesStatus.ashx.cs برای بارگزاری اطلاعات به کار میره (برای نمایش روی صفحه/پیش نمایش)
من به زیر تغییرش دادم

public string HandlerPath = HttpContext.Current.Server.MapPath("~/files/");
اگر از صفحات webform که از masterpage تبعیت می کنند، استفاده می کنید باید در رویداد page_load صفحه کد زیر را وارد کنید

this.Form.Action = "JQueryFileUploader/FileTransferHandler.ashx";
JQueryFileUploader در بالا پوشه حاوی فایل های اپلودر است که handler درون ان می باشد.
به این دلیل که masterPage به طور اتوماتیک محتویات contentPlaceHolder را در یک from قرار میدهد
<form name="aspnetForm" method="post" action="default.aspx" id="aspnetForm">
و form که درون اون تعریف کردیم را نادیده می گیرد(کد صفحه html)

<div id="fileupload">
<form action="JQueryFileUploader3/FileTransferHandler.ashx" method="post" enctype="multipart/form-data">

[تمامی نوشته های بالا مربوط میشه به فایلjQueryFileUpload.Net-master]

+فایل ضمیمه example Asp.NetjQueryFileUpload by shh by preiView قابلیت پیشنمایش عکس داره و فقط از فایل handler.ashx استفاده می کند.

behzad1367
جمعه 10 آذر 1391, 20:12 عصر
داداش خیلی آقایی بتونی این کنترل رو درست کنی چون خیلی دنبال یه همچین کنترلی هستم.در ضمن لینک دمو خراب هست اصلاحش کن

bftarane
چهارشنبه 29 آذر 1391, 10:19 صبح
+فایل ضمیمه example Asp.NetjQueryFileUpload by shh by preiView قابلیت پیشنمایش عکس داره و فقط از فایل handler.ashx استفاده می کند.
شما خودتون امتحان کرديد اينو؟ آخه من اجرا مي کنم index.html رو فايل آپلود رو به شکل فايل آپلود معمولي نشون ميده در ضمن من متوجه نشدم چه کدهايي رو کجا بايد اضافه کنم ميشه در همون پروژه قبلي بگين چيا بايد اضافه بشه؟
ممنونم.

hamed_hossani
چهارشنبه 29 آذر 1391, 20:53 عصر
شما خودتون امتحان کرديد اينو؟ بله
زمانی که به اینترنت وصل نباشین ظاهرش لود نمی شه >این طوری میشه>به خاطر jquery-ui.css است که لود نمیشه!
من از اونی استفاده می کنم که فایل(FileTransferHandler.ashx.cs) توش هست پیش نمایش عکس هم داره!
فایل های که من گذاشتم تو head

<link href="JQueryFileUploader/styles/jquery-ui.css" rel="stylesheet" type="text/css" />
<link href="JQueryFileUploader/styles/jquery.fileupload-ui.css" rel="stylesheet"
type="text/css" />
<link href="JQueryFileUploader/styles/style.css" rel="stylesheet" type="text/css" />

<script src="JQueryFileUploader/scripts/jquery/jquery-ui-v1.8.13.min.js" type="text/javascript"></script>
<script src="JQueryFileUploader/scripts/jquery/jquery.tmpl-beta1.min.js" type="text/javascript"></script>

<script src="JQueryFileUploader/scripts/jquery.iframe-transport.js" type="text/javascript"></script>
<script src="JQueryFileUploader/scripts/jquery.fileupload.js" type="text/javascript"></script>
<script src="JQueryFileUploader/scripts/jquery.fileupload-ui.js" type="text/javascript"></script>
<script src="JQueryFileUploader/scripts/application.js" type="text/javascript"></script>
فایل ها را دانلود کنید بگذارید توی پوشه سایتتون!

bftarane
چهارشنبه 29 آذر 1391, 22:19 عصر
يه سوال ديگه هم دارم. اگه بخواهيم چند تا از اين آپلودرها در صفحات مختلف داشته باشيم مثلاً صفحه درج خبر يکي و صفحه درج مقاله يکي ديگه و بخواهيم عکسها در فولدرهاي جداگانه ذخيره بشن راهي که به ذهن من مي رسه اينه که به ازاي هر فولدر کارهايي که براي يک آپلودر انجام داديم رو تکرار کنيم يعني اينجا 6 تا فايل ashx.cs ميشه. که به نظرم کار جالبي نمي رسه اگه راه بهتري سراغ داريد لطفاً در ميون بزاريد.

hamed_hossani
چهارشنبه 29 آذر 1391, 23:17 عصر
در همون فایل ashx.cs فسمتی برای مسیر داره
سعی کنید با برنامه نویسی با توجه به کارکرد اونو تغییر بدین

public string StorageRoot
{
get
{
//writed by hamed.hossani@gmail.com
return HttpContext.Current.Server.MapPath("~/");// +path;
// ConfigurationManager.AppSettings["StorageRoot"];
}
}
پابلیک است
می تونید set{} هم اضافه کنید و در جاهای دیگه صدا بزنید!