Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > Flash/Flex > Flex
Flex Forum d'entraide sur la programmation Adobe Flex : applications Internet riches (RIA)
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 04/12/2007, 21h09   #1
Membre du Club
 
Inscription : novembre 2006
Messages : 173
Détails du profil
Informations forums :
Inscription : novembre 2006
Messages : 173
Points : 43
Points : 43
Par défaut Upload de Fichier pour PHP processing

Bonjour

je cherche à mettre en place un composant dans une application pour faire un upload de fichier vers un script php qui doit ensuite faire une opération de lecture du contenu du fichier.

dans l'état actuel j'obtiens les traces suivantes une fois l'upload réalisé:
Code :
1
2
3
4
5
6
7
8
9
 
progressHandler: name=4-nov-2007.gpx bytesLoaded=32768 bytesTotal=169869
progressHandler: name=4-nov-2007.gpx bytesLoaded=65536 bytesTotal=169869
progressHandler: name=4-nov-2007.gpx bytesLoaded=98304 bytesTotal=169869
progressHandler: name=4-nov-2007.gpx bytesLoaded=131072 bytesTotal=169869
progressHandler: name=4-nov-2007.gpx bytesLoaded=163840 bytesTotal=169869
progressHandler: name=4-nov-2007.gpx bytesLoaded=169869 bytesTotal=169869
completeHandler: [Event type="complete" bubbles=false cancelable=false eventPhase=2]
[DataEvent type="uploadCompleteData" bubbles=false cancelable=false eventPhase=2 data="0"]

J'aimerais savoir comment interpréter le eventPhase=2 notamment?

le script php nécessite un certain nombre de parametres, est ce que le fait que data="0" signifie que rien ne se passe apres l'upload i.E. les parametres ne sont pas les bons?
lekunfry est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/12/2007, 11h52   #2
Membre du Club
 
Inscription : novembre 2006
Messages : 173
Détails du profil
Informations forums :
Inscription : novembre 2006
Messages : 173
Points : 43
Points : 43
les deux codes suivant font ils la meme chose un upload de fichier avec les parametres tels que présentés dans le code as?


Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300"
	initialize="init()"
	>
 
	<mx:Script>
		<![CDATA[
			import com.project.community.model.CommunityModel;
			import com.project.community.model.EditorModel;
			import mx.controls.Alert;
			import mx.controls.ProgressBar;
			import mx.utils.ObjectUtil;
			import flash.events.*;
	 		import flash.net.FileReference;
		        import flash.net.URLRequest;
 
		    /**
			 *
			 */
			private const UPLOAD_URL : String = "http://server.com/plateform/ul/index.php";
 
 
			private var _progressBar: ProgressBar = new ProgressBar();
			private var _fileRef : FileReference = new FileReference();
			private var _gpsTypes : FileFilter = new FileFilter("Text Files (*.gpx)", "*.gpx");
 
 
 
 
			public function init() : void 
			{
				initListener();
			}
 
 
 
			public function initListener() : void 
			{
				submit.addEventListener(MouseEvent.CLICK, submitClickHandler);
				back.addEventListener(MouseEvent.CLICK, backClickHandler);
 
				_fileRef.addEventListener(Event.SELECT, fileSelectedHandler);
				_fileRef.addEventListener(ProgressEvent.PROGRESS, progressEventHandler);
 
				_fileRef.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); 
		        _fileRef.addEventListener(Event.COMPLETE, uploadCompletedHandler); 
                _fileRef.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
				_fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, serverResponseHandler);
			}
 
 
			  public function httpStatusHandler(event:HTTPStatusEvent): void 
		      {
				trace("httpStatusHandler: " + event);
			  }
 
 
 
			/*public function httpStatusHandler(event:HTTPStatusEvent):void 
			{
 
		         if (event.status != 200)
		         {
		            if (event.status == 500){
		                mx.controls.Alert.show("Probleme d'écriture","Error");
		                return;
		            }
		              if (event.status == 404){
		                mx.controls.Alert.show("Fichier non trouvé","Error");
		                return;
		            }
		             if (event.status == 415){
		                mx.controls.Alert.show("Type de media interdit","Error");
		                return;
		            }
		             if (event.status == 401){
		                mx.controls.Alert.show("Acces refusé","Error");
		                return;
		            }
		            mx.controls.Alert.show("Erreur "+event.status,"Error");
		         }
    	    }
    	    */
 
 
 
 
			/**
			 * function that handles the event: click on browse button
			 */
			 public function fileSelectedHandler(event : Event) : void 
			 {
 
				selectedfile.text = _fileRef.name;
				progressBar.setProgress(0, 100);
				//progressBar.label = "Loading 0%";	
				enabled = true;
				//trace(selectedfile.text);
			  }  
 
 
 
			/**
			 * function that handle the event: click on back button. 
			 */
			public function submitClickHandler(event : MouseEvent) : void 
			{
				var params : URLVariables = new URLVariables();
				var uploadRequest : URLRequest = new URLRequest(UPLOAD_URL);
				params.filename = _fileRef.name;
		        params.sk = CommunityModel.getInstance().serverSessionKey; // "9b166dc3b1a6bf702dfd87b825627b6a";
		        params.dk = "7ffcd213ac5e00a88a2968c6f3530aeb"; 
		        params.type = "track";
 
		    	//affichage de l'erreur exact retournée par Icelio
		    	//params.view_error = true;
 
 
			    uploadRequest.method = URLRequestMethod.POST;
			    uploadRequest.data = params;
			    trace(uploadRequest.url);
			    trace(uploadRequest.data);
			    trace(params.filename); 
			    _fileRef.upload(uploadRequest);
 
 
			//	progressBar.label = "Uploading...";		
 
			//	EditorModel.getInstance().changeEditor(EditorModel.C_NAVIGATOR_NUMBER);
			}
 
			public function progressEventHandler(event : ProgressEvent): void 
			{
				var file:FileReference = FileReference(event.target); 
				trace("progressHandler: name=" + _fileRef.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
				_progressBar.setProgress(event.bytesLoaded, event.bytesTotal);
 
			}
 
			public function uploadCompletedHandler(event : Event):void
			{
				trace("completeHandler: " + event); 
 
			}
 
 
 
			public function serverResponseHandler( event:DataEvent ) :void
			{
		       	trace(event);
				var response : XML = XML( event.data );
				trace(response);
 
			}
 
			/**
			 * function that handle the event: click on back button
			 */
			public function backClickHandler(e : MouseEvent) : void 
			{
				EditorModel.getInstance().changeEditor(EditorModel.C_NAVIGATOR_NUMBER);
			}  
 
 
 
 
		    public function ioErrorHandler (event : IOErrorEvent) : void
			{
			 	trace("ioErrorHandler: " + event); 
			}
 
		]]>
	</mx:Script>
 
	<mx:Panel title="{EditorModel.getInstance().langTraceInserterterTitle}" top="0" bottom="15" left="1" right="10">
 
		<mx:Canvas verticalScrollPolicy="auto" width="100%" height="100%">
 
 
			<mx:TextInput  x="10" y="20" id="selectedfile" />
			<mx:Button x="167" y="20" id="browse"  label="{EditorModel.getInstance().langTraceInserterterBrowser}"
				 click="_fileRef.browse([_gpsTypes])" />
 
 
			<!-- progress bar -->
 
			<mx:ProgressBar label="Transfert Progress" id="progressBar" mode="manual" x="10" y="50"/>
 
 
 
			<!-- submit -->
			<mx:Button id="submit" label="{EditorModel.getInstance().langTraceInserterterValidate}"
				buttonMode="true" useHandCursor="true" width="120"
				styleName="submit" right="10" top="10"
			/>
			<mx:Button id="back" label="{EditorModel.getInstance().langTraceInserterterCancel}"
				buttonMode="true" useHandCursor="true" width="120"
				styleName="cancel" y="65" right="10"
			/>
 
		</mx:Canvas>
 
	</mx:Panel>
</mx:Canvas>


Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
 
define('FOLDER_ROOT', '../..');
$load_param = array('session','template','cnty_tools_main','cnty_tools_action','cnty_conf','error','xss');
require_once('head.php');
 
include PATH_TEMPLATES_CONFIG."/_config_account.php";
$aTemplates['Account_Form'] = file_get_contents($cfg['path_tmpl_list'].'tmpl_trace_new.html');
 
function DoOutput ()
{
    global $rt;
    echo TemplateProcess($rt['output']);
}
$addr = $cfg['this_url'];
 
//$sub_name = substr($_SESSION['sess_key_plateform'], 0, 10);
/*  Send file
    @param  string  $url        Url
    @param  array   $file       File array
    @param  array   $var        Var array
    @param  string  $boundary   Separator
    @return array with header and content client response
 */
function header_build($url, $file, $var = null, $boundary = '---------------------------9633331271588363780939124723') {
 
    $response = null;
 
    $tab = parse_url($url);
	echo ($tab);
   $fp = fsockopen($tab['host'], 80, $errno, $errstr, 30);
 
   $parsingfile = fopen('parsingfile.txt', 'r+');
   fseek($parsingfile, 0); 
   fputs($parsingfile, $tab); 
   fclose($parsingfile);
 
  //$parsingresult = file_get_contents($parsingfile);
  echo ($parsingresult);
 
 
    if ($fp) {
 
        // Build the header
        $header = "POST ".$tab['path']." HTTP/1.0\r\n";
        $header .= "Host: ".$tab['host']."\r\n";
        $header .= "Content-type: multipart/form-data, boundary=$boundary\r\n";
 
        $data = null;
 
        // Add post var
        foreach ($var as $k => $v) {
            $data .="--$boundary\r\n";
            $data .= "Content-Disposition: form-data; name=\"".$k."\"\r\n";
            $data .= "\r\n".$v."\r\n";
        }
 
        // Attach files
        foreach ($file as $f) {
            $data .= "--$boundary\r\n";
            $data .="Content-Disposition: form-data; name=\"ul_files[]\"; filename=\"".basename($f)."\"\r\n";
            $data .= "Content-Type: unknow/unknow\r\n\r\n";
            $data .= file_get_contents($f)."\r\n";
            $data .= "--$boundary\r\n";
        }
 
        $header .= "Content-length: ".strlen($data)."\r\n\r\n";
 
        // Write !
        fwrite($fp, $header.$data);
 
        $data = null;
 
        // Read response
        while (!feof($fp)) {
            $data .= fread($fp, 32);
        }
 
        // Extract header and content
        $data = explode("\n", $data);
        $header = true;
        $tab = null;
        foreach ($data as $k => $v) {
            $v = trim($v);
            if (empty($v)) {
                $header = false;
            }
            $tab[(($header) ? 'header' : 'content')] .= $v;
        }
 
        fclose($fp);
    }
 
    return $tab;
}
 
/*
 
*/
 
$error = 0;
 
//define('MY_DISPLAY_KEY', '7b9e07cae6d80eb026fc5614fa7641b7');
//$_SESSION['sess_key_plateform'] = '6ee357286d2e135480c8f83a21f6b2e4';
if (isset($_FILES) && !empty($_FILES)) {
 
    $out = header_build($addr,
                        array($_FILES['trackfile']['tmp_name']),
                        array('sk' => $_SESSION['sess_key_platform'], 'dk' => MY_DISPLAY_KEY, 'type' => 'track')
                        );
    $content = unserialize($out['content']);
    if (is_array($content)) {
        $msg = 'Erreur durant l\'importation de la trace !';
    } else {
        $msg = 'La trace à bien été importée !';
    }
 
    SetTemplateVar(false, 'MESSAGE_TRACK',  $msg);
} else {
    SetTemplateVar(false, 'MESSAGE_TRACK',  null);
}
 
$rt['output'] = GetTemplate('Account_Form');
DoOutput();
unset($rt);
 
?>
lekunfry est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 11h08.


 
 
 
 
Partenaires

Hébergement Web