[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">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mercadão da Cidade - Ribeirão Preto</title>
<?php
echo $css;
echo $src;
$uploadpath="";
$uploadpath=str_ireplace($_SERVER['DOCUMENT_ROOT'],"", realpath($_SERVER['SCRIPT_FILENAME']));
$uploadpath=str_ireplace("index.php","",$uploadpath);
?>
[removed]
$("document").ready(function()){
$('#uploadifyit').uploadify({
uploader: '<?=$this->config->item('site');?>/system/application/uploadify/uploadify.swf',
script: '<?=$this->config->item('site');?>/system/application/uploadify/uploadify.php',
cancelImg: '<?=$this->config->item('site');?>/system/application/uploadify/cancel.png',
folder: '<?=$this->config->item('site');?>/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('<?php echo site_url('welcome/uploadify');?>',{filearray: response},function(info){ $("#fileinfotarget").append(info);});
},
'onAllComplete': function(event,data){
}
});
});
}
[removed]
</head>
<body>
<div align="center">
<?php echo form_open_multipart("upload/index");?>
<p><label for="filedata">Upload file(s)</label><br />
<?=form_upload(array('name')=>'filedata','id'=>'uploadifyit'));?>
<a href="[removed]$('#uploadifyit').uploadifyUpload();">Upload file(s)</a>
</p>
<?php echo form_close();?>
<div id="fileinfotarget">
</div>
</div>
</body>
</html>
-----------------------------
uploadify.php
-----------------------------
Code: <?
$json= json_decode($this->input->post('filearray'));
?>
<ul>
<li>Link: <a >config->item('site');?>/images/multiplo/<?=$json->{'file_name'}?>"><?=$json->{'filename'}?></a></li>
<li>type: <?=$json->('file_ext');?></li>
<li>Size: <?=$json->('file_size');?></li>
<li>Path: <?=$json->('file_path');?></li>
</ul>
--------
Gracefull to attention and sorry to english erros, by translate.google.com
[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">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mercadão da Cidade - Ribeirão Preto</title>
<?php
echo $css;
echo $src;
$uploadpath="";
$uploadpath=str_ireplace($_SERVER['DOCUMENT_ROOT'],"", realpath($_SERVER['SCRIPT_FILENAME']));
$uploadpath=str_ireplace("index.php","",$uploadpath);
?>
[removed]
$("document").ready(function()){
$('#uploadifyit').uploadify({
uploader: '<?=$this->config->item('site');?>/system/application/uploadify/uploadify.swf',
script: '<?=$this->config->item('site');?>/system/application/uploadify/uploadify.php',
cancelImg: '<?=$this->config->item('site');?>/system/application/uploadify/cancel.png',
folder: '<?=$this->config->item('site');?>/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('<?php echo site_url('welcome/uploadify');?>',{filearray: response},function(info){ $("#fileinfotarget").append(info);});
},
'onAllComplete': function(event,data){
}
});
});
}
[removed]
</head>
<body>
<div align="center">
<?php echo form_open_multipart("upload/index");?>
<p><label for="filedata">Upload file(s)</label><br />
<?
// ERROR IN CODE ...WAS HERE array('name'=>'filedata' ...
?>
<?=form_upload(array('name'=>'filedata','id'=>'uploadifyit'));?>
<a href="[removed]$('#uploadifyit').uploadifyUpload();">Upload file(s)</a>
</p>
<?php echo form_close();?>
<div id="fileinfotarget">
</div>
</div>
</body>
</html>
[eluser]Marlon Souza[/eluser]
Thank Vitoco, I did, and sucess.
Thx
[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
[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: <?php echo form_open_multipart("multiplo/welcome/inserir");?>
<?php $i = 10; for ($j = 1; $j <= $i; $j++): ?>
<div class="form_element">
<label for="photo<?=$j?>">Imagem N°<?=$j?></label>
<?=form_upload(array('name' => 'userfile['.$j.']',
'id' => 'uploadifyit',
'size' => '36'))?>
</div>
<?php endfor ?>
<input type="submit" name="submit" id="submit" value="Salvar">
<?php echo form_close();?>
|