source: trunk/prototype/post.php @ 6071

Revision 6071, 1.2 KB checked in by gustavo, 12 years ago (diff)

Ticket #2676 - Falha ao anexar arquivo no expresso mail

Line 
1<?php
2/* Upload de arquivos e encaminhado para seu respectivo conceito
3 * com o source em base64 melhoria na performace.
4 */
5
6$data = $_POST;
7       
8if( count($_FILES) )
9{
10        $files = array();
11        foreach( $_FILES as $name => $file )
12        {
13                if( is_array( $file['name'] ) )
14                {
15                        foreach( $file['name'] as $key => $value ){
16                                $counter = count($files);
17                                $files[$name.$counter] = array('name' => $file['name'][$counter],
18                                        'type' => $file['type'][$counter],
19                                        'source' => base64_encode(file_get_contents( $file['tmp_name'][$counter], $file['size'][$counter])),
20                                        'size' => $file['size'][$counter],
21                                        'error' => $file['error'][$counter]
22                                );
23                        }
24                }else
25                        $files[$name] = $file;
26        }
27       
28        $_FILES = $files;       
29}
30
31if(isset($data['MAX_FILE_SIZE']))
32        unset($data['MAX_FILE_SIZE']);
33       
34require_once "api/controller.php";
35
36Controller::addFallbackHandler( 0, function($e){ throw $e; } );
37
38$result = array();
39foreach( $data as $concept => &$content )
40{
41        if(!is_array($content))
42                $content = array($content);
43               
44        foreach($content as $key => $value){
45                try{
46                        $result[$concept][] = Controller::put( array( 'concept' => $concept ), $value );
47                }catch(Exception $e){
48                        $result[$concept]['error'] = $e->getMessage();                 
49                }
50        }
51}       
52echo json_encode( $result );
Note: See TracBrowser for help on using the repository browser.