Welcome Guest, Not a member yet? Register   Sign In
Multiple File Upload with Codeigniter + Uploadify
#1

[eluser]Marlon Souza[/eluser]
Hello everyone, I am developing an application for multiple file uploads.

I saw this link (http://vimeo.com/10951360) that the guy got to do, seeing the video, followed and copied the code is generating more error, someone already managed to upload multiple files.

A error is
Parse error: syntax error, unexpected T_DOUBLE_ARROW in [...]/welcome_message.php on line 49

Here my code:
------------------------

Controller:

------------------------
welcome.php
------------------------
Code:
class Welcome extends Controller {
    function Welcome(){
        parent::Controller();
    }
    function index(){
    $this->load->library('form_validation');
        $dados=array('css'=>'<link rel="stylesheet" type="text/css" src="'.$this->config->item('site').'/system/application/uploadify/uploadify.css"/>',
        'src'=>'[removed]config->item('site').'/system/application/uploadify/swfobject.js">[removed]
        [removed]config->item('site').'/system/application/uploadify/jquery-1.3.2.min.js">[removed]
        [removed]config->item('site').'/system/application/uploadify/jquery.uploadify.v2.1.0.min.js">[removed]                                                                            ');
        $this->load->view('multiplo/welcome_message', $dados);
    }
    function inserir(){
        $this->load->library('form_validation');
        $file=$this->input-post('');
        $dados['json']=json_decode('filearray');
        $this->load->view('uploadify/Upload',$dados);
    }
}
------------------------------

View:

------------------------------
welcome_message
------------------------------
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Mercadão da Cidade - Ribeirão Preto&lt;/title&gt;
&lt;?php
echo $css;
echo $src;

$uploadpath="";
$uploadpath=str_ireplace($_SERVER['DOCUMENT_ROOT'],"", realpath($_SERVER['SCRIPT_FILENAME']));
$uploadpath=str_ireplace("index.php","",$uploadpath);
                                
?&gt;
[removed]
    $("document").ready(function()){
        $('#uploadifyit').uploadify({
                uploader: '&lt;?=$this->config->item('site');?&gt;/system/application/uploadify/uploadify.swf',        
                script: '&lt;?=$this->config->item('site');?&gt;/system/application/uploadify/uploadify.php',
                cancelImg: '&lt;?=$this->config->item('site');?&gt;/system/application/uploadify/cancel.png',
                folder: '&lt;?=$this->config->item('site');?&gt;/images/multiplo',
                scriptAcess: 'always',
                multi:true,
                'onError':function(a,b,c,d){
                    if(d.status=404)
                        alert('Not File');
                    else if(d.type==="HTTP")    
                        alert('Error'+d.type+': '+d.info);
                    else if(d.type==="Size error")
                        alert(c.name+' '+d.type+' Limite'+Math.round(d.sizeLimit/1024)+'Kb');
                    else
                        alert('Error'+d.type+': '+d.text);                        
                },
                'onComplete' : function(event,queueID, fileObj, response, data){
                    $.post('&lt;?php echo site_url('welcome/uploadify');?&gt;',{filearray: response},function(info){ $("#fileinfotarget").append(info);});
                },
                'onAllComplete': function(event,data){
                
                }
            });    
        });
    }
[removed]
&lt;/head&gt;
&lt;body&gt;
<div align="center">
    &lt;?php echo form_open_multipart("upload/index");?&gt;
    <p><label for="filedata">Upload file(s)</label><br />
    &lt;?=form_upload(array('name')=>'filedata','id'=>'uploadifyit'));?&gt;
    <a href="[removed]$('#uploadifyit').uploadifyUpload();">Upload file(s)</a>

    </p>
    &lt;?php echo form_close();?&gt;
    <div id="fileinfotarget">
    
    </div>
</div>
&lt;/body&gt;
&lt;/html&gt;

-----------------------------
uploadify.php
-----------------------------
Code:
&lt;?
$json= json_decode($this->input->post('filearray'));
?&gt;

<ul>
    <li>Link: <a >config->item('site');?&gt;/images/multiplo/&lt;?=$json->{'file_name'}?&gt;">&lt;?=$json->{'filename'}?&gt;</a></li>
    <li>type: &lt;?=$json->('file_ext');?&gt;</li>
    <li>Size: &lt;?=$json->('file_size');?&gt;</li>
    <li>Path: &lt;?=$json->('file_path');?&gt;</li>
</ul>
--------
Gracefull to attention and sorry to english erros, by translate.google.com
#2

[eluser]vitoco[/eluser]
THe problem is in your view, you close the array too early , find "// ERROR IN CODE"

[quote author="Marlon Souza" date="1274491619"]Hello everyone, I am developing an application for multiple file uploads.

I saw this link (http://vimeo.com/10951360) that the guy got to do, seeing the video, followed and copied the code is generating more error, someone already managed to upload multiple files.

A error is
Parse error: syntax error, unexpected T_DOUBLE_ARROW in [...]/welcome_message.php on line 49

------------------------------

View:

------------------------------
welcome_message
------------------------------
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Mercadão da Cidade - Ribeirão Preto&lt;/title&gt;
&lt;?php
echo $css;
echo $src;

$uploadpath="";
$uploadpath=str_ireplace($_SERVER['DOCUMENT_ROOT'],"", realpath($_SERVER['SCRIPT_FILENAME']));
$uploadpath=str_ireplace("index.php","",$uploadpath);
                                
?&gt;
[removed]
    $("document").ready(function()){
        $('#uploadifyit').uploadify({
                uploader: '&lt;?=$this->config->item('site');?&gt;/system/application/uploadify/uploadify.swf',        
                script: '&lt;?=$this->config->item('site');?&gt;/system/application/uploadify/uploadify.php',
                cancelImg: '&lt;?=$this->config->item('site');?&gt;/system/application/uploadify/cancel.png',
                folder: '&lt;?=$this->config->item('site');?&gt;/images/multiplo',
                scriptAcess: 'always',
                multi:true,
                'onError':function(a,b,c,d){
                    if(d.status=404)
                        alert('Not File');
                    else if(d.type==="HTTP")    
                        alert('Error'+d.type+': '+d.info);
                    else if(d.type==="Size error")
                        alert(c.name+' '+d.type+' Limite'+Math.round(d.sizeLimit/1024)+'Kb');
                    else
                        alert('Error'+d.type+': '+d.text);                        
                },
                'onComplete' : function(event,queueID, fileObj, response, data){
                    $.post('&lt;?php echo site_url('welcome/uploadify');?&gt;',{filearray: response},function(info){ $("#fileinfotarget").append(info);});
                },
                'onAllComplete': function(event,data){
                
                }
            });    
        });
    }
[removed]
&lt;/head&gt;
&lt;body&gt;
<div align="center">
    &lt;?php echo form_open_multipart("upload/index");?&gt;
    <p><label for="filedata">Upload file(s)</label><br />
&lt;?
    // ERROR IN CODE ...WAS HERE array('name'=>'filedata' ...
?&gt;
    &lt;?=form_upload(array('name'=>'filedata','id'=>'uploadifyit'));?&gt;
    <a href="[removed]$('#uploadifyit').uploadifyUpload();">Upload file(s)</a>

    </p>
    &lt;?php echo form_close();?&gt;
    <div id="fileinfotarget">
    
    </div>
</div>
&lt;/body&gt;
&lt;/html&gt;
#3

[eluser]Marlon Souza[/eluser]
Thank Vitoco, I did, and sucess.

Thx
#4

[eluser]vitoco[/eluser]
You're welcome, another thing, i think that onError, onComplete , onAllComplete doesn't need to be between '' , cause they are defined as methods to overwrite.

Saludos
#5

[eluser]Marlon Souza[/eluser]
I did simple Multiple Upload, no class, just only phpOO

controller
Code:
class Welcome extends Controller {
     function Welcome(){
          parent::Controller();
     }
     function index(){
          $this->load->library('form_validation');
          $dados['msg_erro']="";
          $this->load->view('multiplo/welcome_message', $dados);
     }
     function inserir(){
          $dados['msg_erro']="";
          $this->load->library('form_validation');


          foreach($_FILES['userfile']['tmp_name'] as $item){
               if($item!=""){
                    $uploadFile="";
                    $uploadFile=md5(uniqid(time())).".jpg";
                    $newfile= PATH."/".$uploadFile;
                    if(move_uploaded_file($item, $newfile)){
                         $dados['msg_erro']=$uploadFil$uploadFile."  - Upload"
                    }
                    else{
                         $dados['msg_erro']="Error, Try again";
                    }
              }
       }
    
       $this->load->view('multiplo/welcome_message', $dados);
     }
}

And a more simple View

Code:
&lt;?php echo form_open_multipart("multiplo/welcome/inserir");?&gt;
    
    &lt;?php $i = 10; for ($j = 1; $j <= $i; $j++): ?&gt;
            <div class="form_element">
                <label for="photo&lt;?=$j?&gt;">Imagem N°&lt;?=$j?&gt;</label>
                &lt;?=form_upload(array('name'     => 'userfile['.$j.']',
                                    'id'        => 'uploadifyit',
                                    'size'      => '36'))?&gt;
            </div>
            &lt;?php endfor ?&gt;
  

    &lt;input type="submit" name="submit" id="submit" value="Salvar"&gt;
    &lt;?php echo form_close();?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB