Lomadee, uma nova espécie na web. A maior plataforma de afiliados da América Latina



Luiz Henrique de Angeli

luizdeangeli@gmail.com


Mostrando postagens com marcador PHP. Mostrar todas as postagens
Mostrando postagens com marcador PHP. Mostrar todas as postagens

Componente para Upload com Barra de Progresso

segunda-feira, 3 de agosto de 2009


Fiz um componente para fazer Upload de Arquivo com Barra de Progresso.
Abaixo os arquivos para fazer os testes.

FileUpload.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow
 xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="horizontal"
 title="Selecionar Arquivo"
 showCloseButton="true"
 close="PopUpManager.removePopUp(this);"
 creationComplete="init()">
 
 <mx:NumberFormatter id="numberFormatter" rounding="up"/>
 
 <mx:Form width="100%" height="100%" enabled="{fileUrl.toString()!=''}">
  <mx:FormItem direction="horizontal" width="100%">
   <mx:TextInput id="txt_filename" editable="false" width="160"/>
   <mx:Button id="btn_Localizar" click="localizar();" label="Localizar" icon="@Embed(source='../img/16x16/ico_lupa+.png')" useHandCursor="true" buttonMode="true"/>
   <mx:Button id="btn_enviar" click="enviar();" label="Enviar" icon="@Embed(source='../img/16x16/ico_confirma.png')" useHandCursor="true" buttonMode="true"/>
  </mx:FormItem>  
  <mx:FormItem direction="horizontal" width="100%" visible="{uploadProgresso}" includeInLayout="{uploadProgresso}">
   <mx:ProgressBar id="pgbProgresso" mode="manual" labelPlacement="center" width="100%" label="CARREGANDO {numberFormatter.format(pgbProgresso.percentComplete)}%"/>
  </mx:FormItem>
 </mx:Form>
 
<mx:Script>
 <![CDATA[
  import mx.managers.PopUpManager;
  import mx.controls.Alert;
  
 
  [Bindable] public var fileRef   : FileReference;
  [Bindable] private var uploadProgresso  : Boolean = false;
  [Bindable] private var uploadPorcento  : int = 0;
  
  [Bindable] public var fileUrl    : String;
  [Bindable] public var fileName   : String = "arquivo";  
  [Bindable] public var fileType   : String = "*.*";
  [Bindable] public var fileFilter   : String = "Arquivo";
  [Bindable] public var fileCloseComplete: Boolean = true;
  
  private function init():void
  {
   fileRef = new FileReference();
   fileRef.addEventListener(Event.SELECT, onSelect);
   fileRef.addEventListener(Event.COMPLETE, onUploadComplete);   
   fileRef.addEventListener(ProgressEvent.PROGRESS, progresso);
   fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, fimUpload);   
  }
  
  public function localizar():void
  { 
   var tipos:FileFilter = new FileFilter(fileFilter,fileType);
   var tiposArray:Array = new Array(tipos);
   this.fileRef.browse(tiposArray);
  }
  
  
  public function fimUpload(e:DataEvent):void
  {
   uploadProgresso = false
  }
  
  private function progresso(e:ProgressEvent):void
  {
   pgbProgresso.setProgress(e.bytesLoaded,e.bytesTotal);   
   uploadProgresso = true;
  }
  
  private function erro(e:Event):void{
  
  }
 
  private function onSelect(event:Event):void {
   this.txt_filename.text = fileRef.name;
  }
 
  private function onUploadComplete(event:Event):void
  {
   uploadProgresso = false;
   if(fileCloseComplete)
    PopUpManager.removePopUp(this);
  }
 
  public function enviar():void
  {
   if (fileRef == null) return;
  
   var request:URLRequest = new URLRequest(fileUrl); 
   request.method = URLRequestMethod.POST; 
   fileRef.upload(request, fileName);
  }
 
 ]]>
 </mx:Script>
</mx:TitleWindow>




Usando.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.utils.StringUtil;
   import mx.controls.Alert;
   import mx.managers.PopUpManager;   
   
   private function adicionarArquivo():void
{
 var fileUpload : FileUpload;
 fileUpload = new FileUpload();
 
 fileUpload.fileUrl = "http://www.urldoupload.com.br/upload.php";
 fileUpload.fileType = "*.pdf";
 fileUpload.fileFilter = "Arquivo PDF";
 
 
 PopUpManager.addPopUp(fileUpload,this,true);
 PopUpManager.centerPopUp(fileUpload);
 
 fileUpload.fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, fimUpload);
}
   
   public function fimUpload(e:DataEvent):void
   {    
    if(StringUtil.trim(e.data.toString())=="ERRO")
    {
     Alert.show('Erro ao salvar arquivo!','Atenção!')
    }else{
     Alert.show(e.data,'Atenção!')
     
    }    
   }
   
  ]]>
 </mx:Script>
 <mx:Button x="110" y="50" label="Arquivo" click="adicionarArquivo()"/>
</mx:Application>


upload.php

<?php
 $arquivo = $_FILES["arquivo"] ? $_FILES["arquivo"] : false;

 $retorno="ERRO";
 
 if($arquivo)
 {
  $url = "./pastadosarquivos/";
  
  if(@move_uploaded_file($arquivo["tmp_name"],$url."".basename($arquivo["tmp_name"]))){
   $retorno = basename($arquivo["tmp_name"]); 
  }
 } 
 
 echo $retorno;
 
?>

Query String

terça-feira, 14 de julho de 2009

Abaixo um exemplo de como passar parametros do HTML ou PHP para o Flex.

QueryString.html


AC_FL_RunContent(
   "src", "QueryString",
   "width", "100%",
   "height", "100%",
   "align", "middle",
   "id", "QueryString",
   "quality", "high",
   "bgcolor", "#869ca7",
   "name", "QueryString",
   "allowScriptAccess","sameDomain",
   "type", "application/x-shockwave-flash",
   "pluginspage", "http://www.adobe.com/go/getflashplayer",
   "FlashVars","param1¶m2¶m3"
);


QueryString.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
 creationComplete="init()">
 <mx:Script>
  <![CDATA[
   import mx.controls.Alert;
   
   private function init():void
   {
    var obj : Object = Application.application.parameters;
    var item : String;
    for(item in obj)
    {
     Alert.show(item.toString());
    }
    
   }
  ]]>
 </mx:Script>
</mx:Application>


Demarcando Área em Flex

segunda-feira, 13 de julho de 2009


Em um projeto em Flex precisei fazer uma demarcação de área, para isso utilizei um componte de polígono que encontrei na internet, que possibilita demarcar 'N' pontos e não só X e Y.

O componte utilizado foi o seguinte : http://www.degrafa.org/source/Polygon/Polygon.html

Link do Projeto - http://www.ead.cesumar.br/polos/


Não posso disponibilizar o código fonte.
Mas caso necessário posso passar algumas dicas de como foi feito.

Acessando o PHP com Flex

Segue abaixo um link para um screencast do Fábio Vedovelli mostrando como usar o AMFPHP para trafegar dados entre a interface e o banco de dados.

Screencast - http://www.vedovelli.com.br/?p=66

Arquivos - http://www.vedovelli.com.br/screencasts/screencast005_21092007/screencastAMF.rar

Retirado de http://www.vedovelli.com.br/
Fábio Vedovelli


Submarino.com.br
Submarino.com.br