티스토리 뷰
FileUpDown.mxml
< ?xml version="1.0" encoding="utf-8"?>
< mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private var fr:FileReference;;
public function Download():void {
fr = new FileReference();
fr.addEventListener(Event.OPEN,onOpenFile);
fr.addEventListener(ProgressEvent.PROGRESS,onFileProgress);
fr.addEventListener(Event.COMPLETE,onCompleteDownload);
var request:URLRequest = new URLRequest();
request.url = "rank.tar.gz";
try {
fr.download(request);
} catch (e:SecurityError){
Alert.show(e.toString());
}
}
public function onOpenFile(event:Event):void {
dpg.label = `다운로드 %3%%`;
}
public function onCompleteDownload(event:Event):void {
Alert.show(`다운로드 완료`);
}
public function onFileProgress(event:ProgressEvent):void {
dpg.setProgress(event.bytesLoaded,event.bytesTotal);
}
public function Upload():void {
fr = new FileReference();
fr.addEventListener(Event.SELECT,onUploadSelectFile);
fr.addEventListener(Event.OPEN,onUploadOpenFile);
fr.addEventListener(ProgressEvent.PROGRESS,onUploadFileProgress);
fr.addEventListener(Event.COMPLETE,onUploadCompleteDownload);
var imgFilter:FileFilter = new FileFilter("Images(*.png;*.gif;*.jpg)","*.png;*.gif;*.jpg");
var arcFilter:FileFilter = new FileFilter("Archives(*.zip;*.gz;*.tar)","*.zip;*.gz;*.tar");
var allFilter:FileFilter = new FileFilter("All(*.*)","*.*");
fr.browse([imgFilter,arcFilter,allFilter]);
}
public function onUploadSelectFile(event:Event):void {
var request:URLRequest = new URLRequest();
request.url = "upload.php";
try {
fr.upload(request,"file");
} catch (e:SecurityError){
Alert.show(e.toString());
}
}
public function onUploadOpenFile(event:Event):void {
upg.label = `업로드 %3%%`;
}
public function onUploadCompleteDownload(event:Event):void {
Alert.show(`업로드 완료`);
}
public function onUploadFileProgress(event:ProgressEvent):void {
upg.setProgress(event.bytesLoaded,event.bytesTotal);
}
]]>
</mx:Script>
<mx:Button x="10" y="10" label="Dowload" click="Download()"/>
<mx:Label id="filepg" x="93" y="12"/>
<mx:ProgressBar x="10" y="38" width="351" label="" id="dpg" mode="manual"/>
<mx:ProgressBar x="10" y="110" width="351" label="" id="upg" mode="manual"/>
<mx:Button x="10" y="80" label="Upload" click="Upload()" width="75"/>
< /mx:Application>
upload.php
< ?
$file_temp = $_FILES[`file`][`tmp_name`];
$file_name = $_FILES[`file`][`name`];
$file_size = $_FILES[`file`][`size`];
$updir = "D:/wwwroot/test/html/upload";
if(!empty($file_name)){
$filename = sprintf("%s/%s",$updir,$file_name);
$filename = iconv("UTF-8", "EUC-KR",$filename); // 한글처리
if(!file_exists($filename)) {
if(move_uploaded_file($file_temp,$filename)){
} else {
}
}
}
fclose($fp);
?>
============================================================================================
해외에서 구한 소스인데, 아직 실험해 보지 못했다.
원래는 정책적으로는 불가능한 멀티 다운로드 인데...
어떤식으로 구현했는지 확인해 볼 요량으로 저장한다...
(안된다는 식의 댓글 거절한다.. -_-; 나도 시험을 안해봤기 때문에..)
< s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="200"
title=" Updater"
showStatusBar="false">
<fx:Style source="Main.css"/>
<fx:Script>
<![CDATA[
private function download_clickHandler(event:MouseEvent):void
{
var filearray:Array = new Array();
filearray[0]="pregame.jpg";
filearray[1]="01.jpg";
filearray[2]="02.jpg";
filearray[3]="03.jpg";
filearray[4]="04.jpg";
filearray[5]="05.jpg";
filearray[6]="06.jpg";
filearray[7]="07.jpg";
filearray[8]="08.jpg";
filearray[9]="09.jpg";
filearray[10]="10.jpg";
for (var i:uint; i < filearray.length; i++) {
var remoteURL = "http://www.domain.com/" + filearray[i];
var localURL = "C:/dir/" + filearray[i];
downloadFile(remoteURL, localURL);
}
function downloadFile(url, fileName) {
// Create the stream for the data request
var urlStream = new URLStream();
// Used to initiate request for remote file
var request = new URLRequest(url);
// Create file stream
var fileStream = new FileStream();
// Create a reference to a location on disk
var file = File.desktopDirectory.resolvePath(fileName);
// Called as download progresses
var writeFile = function()
{
// Write to file
if (urlStream.bytesAvailable > 51200)
{
var dataBuffer = new ByteArray();
urlStream.readBytes(dataBuffer, 0, urlStream.bytesAvailable);
fileStream.writeBytes(dataBuffer, 0, dataBuffer.length);
}
return true;
}
// Called when download completes
var finishWriteFile = function()
{
// Write to file
if(urlStream.bytesAvailable > 0)
{
var dataBuffer = new ByteArray();
urlStream.readBytes(dataBuffer, 0, urlStream.bytesAvailable);
fileStream.writeBytes(dataBuffer, 0, dataBuffer.length);
}
// Close streams
fileStream.close();
urlStream.close();
return true;
}
// Initiate download
fileStream.openAsync(file, FileMode.WRITE);
urlStream.load(request);
// Add event listeners
urlStream.addEventListener(Event.COMPLETE, finishWriteFile);
urlStream.addEventListener(ProgressEvent.PROGRESS, writeFile);
}
}
]]>
< /fx:Script>
< fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
< /fx:Declarations>
< mx:Image x="0" y="0" source="background.jpg"/>
< s:Button x="85" y="85" label="Update" id="download" click="download_clickHandler(event)" color="#FFFFFF" fontSize="30"/>
'Language > Flex' 카테고리의 다른 글
[ Flex ][ Source ] Control mxml (0) | 2015.11.29 |
---|---|
[ Flex ][ Source ] MouseEventMOUSE_WHEEL 포커스 버그 (0) | 2015.11.29 |
[ Flex ][ Source ] Image 에서 resize 했을때 화질 보정 (0) | 2015.11.29 |
[ Flex ][ Source ] BitmapData - 투명 (0) | 2015.11.29 |
[ Flex ][ Source ] Flex 배경 투명하게 만들기 (0) | 2015.11.29 |