Welcome Guest, Not a member yet? Register   Sign In
Help!! I can upload anything with codeigniter
#1

[eluser]adekenny[/eluser]
Hi,

I really need help fast, there's this project i'm working on and i'm trying to incorporate a page that allows users to upload images to a directory. The problem is that it's just not working at all. I'v checked the code with the example on the user guide that there seems to be no problem with it.

When i clicked the upload buttom it just wasn't giving any response at all - no even any error message.

What are my not getting right?

please see my controller code below.



<?php

class Upload extends Controller
{

var $base;
var $css;
var $my_menu;

function Upload()
{
parent::Controller();
$this->base = $this->config->item('base_url');
$this->css = $this->config->item('css');
$this->load->library('menu');
$this->my_menu = $this->menu->show_menu();
$this->load->library('upload');
$this->load->library('session');
$this->load->helper(array('form', 'url'));
}


function do_upload()
{
if(!$this->upload->do_upload())
{
$data['menu'] = $this->my_menu;
$data['base'] = $this->base;
$data['css'] = $this->css;

$error = array('error' => $this->upload->display_errors());

$data['error'] = $error;
$this->load->view('photo_upload_failed', $data);
}
else
{
$data['menu'] = $this->my_menu;
$data['base'] = $this->base;
$data['css'] = $this->css;

$data = array ('upload_data' => $this->upload->data());


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

}

?>


I've already created a file in my config folder where i set all the default settings. Please see below.

<?php

if(!defined('BASEPATH'))
{
exit;
}
else
{

$config['upload_path'] = 'uploads';

$config['allowed_types'] = 'gif|jpg|png';

$config['max_size'] = '40';

$config['max_width'] = '50';

$config['max_height'] = '60';

$config['remove_spaces'] = TRUE;
}

?>


Many Thanks
adekenny - Nigeria
#2

[eluser]pickupman[/eluser]
Could you please post your view, so we can see what the form looks like. Are you using any javascript controls like jQuery where you are binding the click event of the submit button? Do you have write permissions to the uploads folder? What OS environment are you working on?
#3

[eluser]adekenny[/eluser]
I've attached the view to this post.

It was just displaying "ARRAY" instead of an error message or success message.

The OS i'm using is windows XP and Windows 7 Professioal.

Thanks for replying
#4

[eluser]adekenny[/eluser]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;Sectech Univeristy Website&lt;/title&gt;
&lt;base href= &lt;?php echo "$base"; ?&gt; /&gt;
&lt;link rel="stylesheet" type="text/css" href= "&lt;?php echo "$base/$css"; ?&gt;" /&gt;
&lt;/head&gt;

&lt;body&gt;

<div id="main_container">
<div id="header"><img src="header.jpg" /></div>
<div id="menu">&lt;?php echo $menu; ?&gt;</div>
<div id="content">
<h3>Online Registration</h3>
<p><span style="color:#990000; font-weight:bold">Uploading your picture.</span> </p>
<br />

&lt;?php

$this->load->library('session');

$first_name = $this->session->userdata('firstname');
$last_name = $this->session->userdata('lastname');

echo "<p>Passport size photo for: $first_name&nbsp;&nbsp;$last_name&nbsp;is being uploaded.</p>";
?&gt;
&lt;?php

$this->load->helper('form');
$this->load->helper('url');



echo'<br>';

echo form_open_multipart('upload/do_upload');

echo'<table>';
echo'<tr>';
echo'<td>';

echo form_upload($data);
echo'<br>';
echo'<br>';
echo form_submit('mysubmit', 'Submit Post!');
?&gt;
<br /><br /><br /><br />

</div>
<div id="footer">

<P class="copyright">Copyright &copy; 2010 Sectech University</P>
<p class="designer">powered by <A href="http://www.sectechsystems.com">Sectech Systems</A></p>
</div>
</div>
</div>

</div>
&lt;/body&gt;
&lt;/html&gt;
#5

[eluser]adekenny[/eluser]
This is the view the controller is meant to call if the upload fails.

&lt;?php

$this->load->helper('form');


echo $error;
echo'<br>';

echo form_open_multipart('upload/do_upload');

echo'<table>';
echo'<tr>';
echo'<td>';
echo form_upload('$data');
echo'<br>';
echo'<br>';
echo form_submit('mysubmit', 'Submit Post!');

echo form_close();
?&gt;
#6

[eluser]pickupman[/eluser]
Try this:
Code:
//In View
$this->load->helper('form');
$this->load->helper('url');

echo $this->upload->display_errors('<p>', '</p>');

echo form_open_multipart('upload/do_upload');

echo '<p>'.form_label('Choose Image','userfile').'<br/>'.form_upload('userfile').'</p>';

echo '<p>'.form_submit('mysubmit', 'Submit Post!').'</p>';

echo form_close();
It appears you were not setting the field name for the file input. This should help. If you are able to upload, but you are getting errors you may want to check file permissions on your temporary folder. Run phpinfo() function and find the temp folder. Probably c:\windows\temp( or tmp) and make sure it has write permissions.
#7

[eluser]Twisted1919[/eluser]
On windows there's no need to check files write/read perms .
#8

[eluser]pickupman[/eluser]
[quote author="Twisted1919" date="1272594244"]On windows there's no need to check files write/read perms .[/quote]
Yes there is especially with XP Pro or greater. Some folders can have user permissions just like *nix, or be checked "Read Only". Make sure folder is not read only, and the group User is check for Full Access.
#9

[eluser]adekenny[/eluser]
When i tried the code you sent, i got the following error message.

Severity: Notice

Message: Undefined property: CI_Loader::$upload

Filename: views/photo_upload.php

Line Number: 35


Fatal error: Call to a member function display_errors() on a non-object in C:\Program Files (x86)\EasyPHP 2.0b1\www\system\application\views\photo_upload.php on line 35




I've set the right file permission for the folder i'm uploading the files into. Could it be an operating systems issue?
#10

[eluser]pickupman[/eluser]
Replace this line:
Code:
echo $this->upload->display_errors('<p>', '</p>');

With this:
Code:
echo @$errors;

In your controller where you are checking upload add:
Code:
$data['errors'] = $this->upload->display_errors('<p>', '</p>');




Theme © iAndrew 2016 - Forum software by © MyBB