Welcome Guest, Not a member yet? Register   Sign In
Tutorial File Upload Class Problem
#1

[eluser]davehedgehog[/eluser]
Hey, so I was doing the tutorial and for the life of me I cant figure out why this error message keeps presenting itself?

Parse error: syntax error, unexpected T_STRING, expecting ')' .......on line 13

here is the controller:
<?php

class Upload extends CI_Controller {

public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url));
}

public function index()
{
$this->load->view('upload_form'), array('error') => ''));
}

public function do_upload()
{
$config['upload_path']='./uploads/';
$config['allowed_types']='gif|jpg|png';
$config['max_size']='100';
$config['max_width']='1024';
$config['max_height']='768';

$this->load->library('upload',$config);

if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form',$error);
}
else
{
$data = array('upload_data' => $this->upload->data());

$this->load->view(upload_success', $data);
}
}
}
?>

really appreciate any help asap :/
#2

[eluser]Sky Warden[/eluser]
That error means there's a typo in your script. I found it in this part :
Code:
public function index()
{
  $this->load->view(‘upload_form’), array(‘error’) => ‘’));
}

Try to edit it into this :

Code:
public function index()
{
  $this->load->view('upload_form', array('error') => '');
}
#3

[eluser]davehedgehog[/eluser]
Woah cheers for the awesome fast reply. Sorry was quite late when I posted this so proberly wasnt that clear, either way doesn't work =( get the same error message. Ive tried different variations and also tried removing the function and it just prompts me with the same error =S any ideas?
#4

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

Please remember to wrap your code in [code][/code] tags. It makes your code much easier to read. Smile

Please use the following code:
Code:
public function index()
{
    $this->load->view('upload_form', array('error' => ''));
}
#5

[eluser]davehedgehog[/eluser]
Thanks =)

and yeah Ill try and remeber to do that thanks again =)

unfortunately that code still makes no difference, the problem still occurs :/
#6

[eluser]TheFuzzy0ne[/eluser]
What's the error you have now? It can't be the same one. If it is, then you haven't updated the code correctly.
#7

[eluser]davehedgehog[/eluser]
I re-did the whole page again using a different editor and it worked :S.

same code, really weird.

cheers for your help tho dude =)
#8

[eluser]davehedgehog[/eluser]
Ok...same area, new problem was wondering if you guys could help.

Basically I cant upload the file and keep getting 404

I have configured the Url etc and think it reads right like this:


www.####.com/upload/do_upload

Now my route config file reads:

Code:
$route['upload/upload_success'] = 'upload/upload_success';
$route['upload'] = 'upload';

My View is slightly different from the tutorial to allow me to browser folders.

Code:
<html>
<head>
<title>Upload Form</title>
</head>
<body>

<?php echo $error;?>

<div id="upload">
&lt;?php
echo form_open_multipart('upload/do_upload');
echo form_upload('userfile');
echo form_submit('upload', 'Upload');
echo form_close();
?&gt;  
</div>
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

oh and the Success view

Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Upload Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

<h3> Your file uploaded successfully!</h3>

<ul>

&lt;?php foreach ($upload_data as $item => $value):?&gt;
<li>&lt;?php echo $item;?&gt;: &lt;?php echo $value;?&gt;</li>
&lt;?php endforeach;?&gt;
</ul>

<p>&lt;?php echo anchor('upload', 'Upload another file!');?&gt;</p>


&lt;/body&gt;
&lt;/html&gt;


And the Controller file:

Code:
&lt;?php

class Upload extends CI_Controller {

function __construct()
{
  parent::__construct();
  $this->load->helper(array('form', 'url'));
}

function index()
{
  $this->load->view('upload_form', array('error' => ' ' ));
}

function do_upload()
{
  $config['upload_path'] = './uploads/';
  $config['allowed_types'] = 'gif|jpg|png';
  $config['max_size'] = '100';
  $config['max_width']  = '1024';
  $config['max_height']  = '768';

  $this->load->library('upload', $config);

  if ( ! $this->upload->do_upload())
  {
   $error = array('error' => $this->upload->display_errors());

   $this->load->view('upload_form', $error);
  }
  else
  {
   $data = array('upload_data' => $this->upload->data());

   $this->load->view('upload_success', $data);
  }
}
}
?&gt;

I have also set the uploads folder at the root with permissions set to 0777, as you may gether Ive been tinkering with different options most of the day and still baffled by the 404 =S

Any help?
#9

[eluser]TheFuzzy0ne[/eluser]
Your routes don't serve any purpose. It makes no sense rerouting to an identical URI. You should be able to safely remove those routes, since they basically do nothing.

Also, please check the source code for the upload form, and double check that the URL is correct, by copying and pasting it directly into your browser.
#10

[eluser]davehedgehog[/eluser]
Right...

But I still need

Code:
$route['upload'] = 'upload';

to use the upload_form? yeah

and slightly confused, source code of which upload form the view of controller?...or helper?




Theme © iAndrew 2016 - Forum software by © MyBB