[eluser]James_B[/eluser]
Hi guys I have been following a tutorial online to upload an image to a page but when I upload something I get an error message: The file path does not seem to be valid. And I also get this error instead of seeing you did not select a file to upload error when I select upload without actually selecting any files
What I'm aiming to do is simply display the image to the screen once its uploaded
Ive tried creating an images folder in my root folder where the system folder is, but to no avail
What am i doing wrong?
Code:
<?php
class HomeProfile extends CI_Controller
{
function HomeProfile()
{
parent::__construct();
$this->load->model("profiles");
$this->load->model("profileimages");
$this->load->helper(array('form', 'url'));
}
function upload()
{
$config['upload_path'] = '/images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
//fail show upload form
if (! $this->upload->do_upload())
{
$error = array('error'=>$this->upload->display_errors());
$username = $this->session->userdata('username');
$viewData['username'] = $username;
$viewData['profileText'] = $this->profiles->getProfileText($username);
$this->load->view('shared/header');
$this->load->view('homeprofile/homeprofiletitle', $viewData);
$this->load->view('shared/nav');
$this->load->view('homeprofile/upload_fail', $error);
$this->load->view('homeprofile/homeprofileview', $viewData, array('error' => ' ' ));
$this->load->view('shared/footer');
}
else
{
$file_data = $this->upload->data();
$data['img'] = base_url().'/images/'.$file_data['file_name'];
$this->load->view('upload_success', $data);
$username = $this->session->userdata('username');
}
}
function index()
{
$username = $this->session->userdata('username');
$viewData['username'] = $username;
$viewData['profileText'] = $this->profiles->getProfileText($username);
$this->load->view('shared/header');
$this->load->view('homeprofile/homeprofiletitle', $viewData);
$this->load->view('shared/nav');
$this->load->view('homeprofile/upload_form' );
$this->load->view('homeprofile/homeprofileview', $viewData );
$this->load->view('shared/footer');
}
}
Here are my view files:
upload form:
This file present the form onto the screen
Code:
<div id="maincontent">
<div id="primary">
<?=form_open_multipart('homeprofile/upload');?>
<input type="file" name="userfile" />
<?=form_submit('submit', 'upload')?>
<?=form_close();?>
</div>
</div>
upload fail:
<div id="maincontent">
<div id="primary">
<?php echo $error;?>
<?=form_open_multipart('homeprofile/upload');?>
<input type="file" name="userfile" />
<?=form_submit('submit', 'upload')?>
<?=form_close();?>
</div>
</div>
upload success:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<h3>Your file was successfully uploaded!</h3>
<img src="<?php echo $img?>" width="300" height="300"/>
<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>
</body>
</html>